Uploaded image for project: 'Apache Cordova'
  1. Apache Cordova
  2. CB-4858

Android InAppBrowser does not function properly on 4.3

VotersWatch issueWatchersLinkUpdate Comment AuthorReplace String in CommentUpdate Comment VisibilityDelete Comments
    XMLWordPrintableJSON

Details

    Description

      Try using the full example for the executeScript on a 4.3 emulator.
      http://cordova.apache.org/docs/en/3.0.0/cordova_inappbrowser_inappbrowser.md.html#executeScript

      You will get a syntax issue around the replaceHeaderImage function it is missing a }; at the end of the executeScript call.

      Correct function should look like:

          function replaceHeaderImage() {
              iabRef.executeScript({
                  code: "var img=document.querySelector('#header img'); img.src='http://cordova.apache.org/images/cordova_bot.png';"
              }, function() {
                  alert("Image Element Successfully Hijacked");
              });
          }
      

      Anyway if you run this sample it will fail on a 4.3 emulator with the following stack trace but it will work fine on a 4.0 emulator.

      09-17 15:45:34.236: W/webview_proxy(2553): java.lang.Throwable: Warning: A WebView method was called on thread 'WebViewCoreThread'. All WebView methods must be called on the UI thread. Future versions of WebView may not support use on other threads.
      09-17 15:45:34.236: W/webview_proxy(2553): 	at android.webkit.WebView.checkThread(WebView.java:1918)
      09-17 15:45:34.236: W/webview_proxy(2553): 	at android.webkit.WebView.loadUrl(WebView.java:771)
      09-17 15:45:34.236: W/webview_proxy(2553): 	at org.apache.cordova.inappbrowser.InAppBrowser.injectDeferredObject(InAppBrowser.java:245)
      09-17 15:45:34.236: W/webview_proxy(2553): 	at org.apache.cordova.inappbrowser.InAppBrowser.execute(InAppBrowser.java:169)
      09-17 15:45:34.236: W/webview_proxy(2553): 	at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:65)
      09-17 15:45:34.236: W/webview_proxy(2553): 	at org.apache.cordova.PluginManager.execHelper(PluginManager.java:229)
      09-17 15:45:34.236: W/webview_proxy(2553): 	at org.apache.cordova.PluginManager.exec(PluginManager.java:214)
      09-17 15:45:34.236: W/webview_proxy(2553): 	at org.apache.cordova.ExposedJsApi.exec(ExposedJsApi.java:53)
      09-17 15:45:34.236: W/webview_proxy(2553): 	at android.webkit.JWebCoreJavaBridge.setNetworkOnLine(Native Method)
      09-17 15:45:34.236: W/webview_proxy(2553): 	at android.webkit.JWebCoreJavaBridge.setNetworkOnLine(Native Method)
      09-17 15:45:34.236: W/webview_proxy(2553): 	at android.webkit.WebViewCore$EventHub$1.handleMessage(WebViewCore.java:1431)
      09-17 15:45:34.236: W/webview_proxy(2553): 	at android.os.Handler.dispatchMessage(Handler.java:99)
      09-17 15:45:34.236: W/webview_proxy(2553): 	at android.os.Looper.loop(Looper.java:137)
      09-17 15:45:34.236: W/webview_proxy(2553): 	at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:814)
      09-17 15:45:34.236: W/webview_proxy(2553): 	at java.lang.Thread.run(Thread.java:841)
      09-17 15:45:34.236: W/System.err(2553): java.lang.RuntimeException: java.lang.Throwable: Warning: A WebView method was called on thread 'WebViewCoreThread'. All WebView methods must be called on the UI thread. Future versions of WebView may not support use on other threads.
      09-17 15:45:34.246: W/System.err(2553): 	at android.webkit.WebView.checkThread(WebView.java:1927)
      09-17 15:45:34.246: W/System.err(2553): 	at android.webkit.WebView.loadUrl(WebView.java:771)
      09-17 15:45:34.246: W/System.err(2553): 	at org.apache.cordova.inappbrowser.InAppBrowser.injectDeferredObject(InAppBrowser.java:245)
      09-17 15:45:34.246: W/System.err(2553): 	at org.apache.cordova.inappbrowser.InAppBrowser.execute(InAppBrowser.java:169)
      09-17 15:45:34.246: W/System.err(2553): 	at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:65)
      09-17 15:45:34.246: W/System.err(2553): 	at org.apache.cordova.PluginManager.execHelper(PluginManager.java:229)
      09-17 15:45:34.246: W/System.err(2553): 	at org.apache.cordova.PluginManager.exec(PluginManager.java:214)
      09-17 15:45:34.246: W/System.err(2553): 	at org.apache.cordova.ExposedJsApi.exec(ExposedJsApi.java:53)
      09-17 15:45:34.246: W/System.err(2553): 	at android.webkit.JWebCoreJavaBridge.setNetworkOnLine(Native Method)
      09-17 15:45:34.246: W/System.err(2553): 	at android.webkit.JWebCoreJavaBridge.setNetworkOnLine(Native Method)
      09-17 15:45:34.246: W/System.err(2553): 	at android.webkit.WebViewCore$EventHub$1.handleMessage(WebViewCore.java:1431)
      09-17 15:45:34.246: W/System.err(2553): 	at android.os.Handler.dispatchMessage(Handler.java:99)
      09-17 15:45:34.246: W/System.err(2553): 	at android.os.Looper.loop(Looper.java:137)
      09-17 15:45:34.246: W/System.err(2553): 	at android.webkit.WebViewCore$WebCoreThread.run(WebViewCore.java:814)
      09-17 15:45:34.246: W/System.err(2553): 	at java.lang.Thread.run(Thread.java:841)
      09-17 15:45:34.246: W/System.err(2553): Caused by: java.lang.Throwable: Warning: A WebView method was called on thread 'WebViewCoreThread'. All WebView methods must be called on the UI thread. Future versions of WebView may not support use on other threads.
      09-17 15:45:34.246: W/System.err(2553): 	at android.webkit.WebView.checkThread(WebView.java:1918)
      09-17 15:45:34.246: W/System.err(2553): 	... 14 more
      

      This is related to CB-4586 but is by no means a minor issue. The Android InAppBrowser code needs to run all webview methods on the UI thread now.

      Here are web thread related issues:
      1. Loading a relative url will fail in the InAppBrowser because the updateUrl method is calling webView.getUrl() outside the UI thread.

      2. Execute script will fail because injectDeferredObject is calling inAppWebView.loadUrl outside the UI thread.

      Attachments

        Activity

          This comment will be Viewable by All Users Viewable by All Users
          Cancel

          People

            agrieve Andrew Grieve
            mpridham Marcus Pridham
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Issue deployment