Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-25859

Android: Delay WebView Ti.App.fireEvent() to be fired after page load

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Medium
    • Resolution: Won't Do
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Android
    • Story Points:
      3

      Description

      Summary:
      The JavaScript within a WebView's HTML can call Ti.App.fireEvent() to communicate with the Titanium JavaScript side. It currently fires events immediately. The problem with this is if the listener immediately calls WebView.evalJS() to communicate back, it'll always timeout on Android if the web page hasn't finished loading yet and the Titanium runtime runs on the main UI thread (the default). This makes it less convenient to use.

      Steps to Reproduce:

      1. Build and run attached WebViewInteropTest.js on Android.
      2. Observe the Android log.

      Result:
      An Timeout waiting to evaluate JS warning message appears in the log.

      Expected Result:
      The evalJS() calls should succeed. A countdown message "Reload in: X" should appear in the web page, starting from 5. When it counts down to zero, the page should reload.

      Cause:
      The WebView.evalJS() call will not work until the "load" event has been received from the WebView. This is because Titanium injects a "polling" script into the web page in the WebViewClient.onPageFinished() call...
      https://github.com/appcelerator/titanium_mobile/blob/master/android/modules/ui/src/java/ti/modules/titanium/ui/widget/webview/TiWebViewClient.java#L45

      This polling script is responsible for fetching/evaluating the script added to the stack by the evalJS() call...
      https://github.com/appcelerator/titanium_mobile/blob/master/android/modules/ui/src/java/ti/modules/titanium/ui/widget/webview/TiWebViewBinding.java#L151

      Since evalJS() is getting called before the web page has finished loading, the evalJS() call will always fail with a timeout warning when the Titanium runtime runs on the main UI thread.

      Recommended Solution:
      Queue all Ti.App.fireEvent() calls made within the HTML and do not fire them until the page has finished loading.

      Work-Around:
      Use the new async version of WebView.evalJS() that was introduced into 7.5.0. It does not have this issue.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                jquick Joshua Quick
                Reporter:
                jquick Joshua Quick
                Reviewer:
                Gary Mathews
                Tester:
                Lokesh Choudhary
              • Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Backbone Issue Sync

                  • Backbone Issue Sync is enabled for your project, but we do not have any synchronization info for this issue.

                    Git Integration