{ "id": "171294", "key": "TIMOB-25859", "fields": { "issuetype": { "id": "4", "description": "An improvement or enhancement to an existing feature or task.", "name": "Improvement", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [], "resolution": { "id": "10100", "description": "This issue won't be actioned.", "name": "Won't Do" }, "resolutiondate": "2018-10-24T21:10:00.000+0000", "created": "2018-03-12T21:31:53.000+0000", "priority": { "name": "Medium", "id": "3" }, "labels": [ "android", "evalJS", "webview" ], "versions": [], "issuelinks": [ { "id": "56364", "type": { "id": "10003", "name": "Relates", "inward": "relates to", "outward": "relates to" }, "inwardIssue": { "id": "171129", "key": "TIMOB-25786", "fields": { "summary": "Android: WebView eval JS timeout error ", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "priority": { "name": "None", "id": "6" }, "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false } } } } ], "assignee": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "updated": "2018-10-24T21:10:50.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "10202", "name": "Android", "description": "Android Platform" } ], "description": "*Summary:*\r\nThe 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.\r\n\r\n*Steps to Reproduce:*\r\n# Build and run attached [^WebViewInteropTest.js] on Android.\r\n# Observe the Android log.\r\n\r\n*Result:*\r\nAn {{Timeout waiting to evaluate JS}} warning message appears in the log.\r\n\r\n*Expected Result:*\r\nThe {{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.\r\n\r\n*Cause:*\r\nThe {{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...\r\nhttps://github.com/appcelerator/titanium_mobile/blob/master/android/modules/ui/src/java/ti/modules/titanium/ui/widget/webview/TiWebViewClient.java#L45\r\n\r\nThis polling script is responsible for fetching/evaluating the script added to the stack by the {{evalJS()}} call...\r\nhttps://github.com/appcelerator/titanium_mobile/blob/master/android/modules/ui/src/java/ti/modules/titanium/ui/widget/webview/TiWebViewBinding.java#L151\r\n\r\nSince {{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.\r\n\r\n*Recommended Solution:*\r\nQueue all {{Ti.App.fireEvent()}} calls made within the HTML and do not fire them until the page has finished loading.\r\n\r\n*Work-Around:*\r\nUse the new async version of {{WebView.evalJS()}} that was introduced into 7.5.0. It does not have this issue.\r\n", "attachment": [ { "id": "65770", "filename": "WebViewInteropTest.js", "author": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2018-10-24T21:03:12.000+0000", "size": 2012, "mimeType": "application/x-javascript" } ], "flagged": false, "summary": "Android: Delay WebView Ti.App.fireEvent() to be fired after page load", "creator": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "subtasks": [], "reporter": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "environment": null, "comment": { "comments": [ { "id": "435525", "author": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "body": "PR (master): https://github.com/appcelerator/titanium_mobile/pull/9931", "updateAuthor": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2018-03-12T23:50:48.000+0000", "updated": "2018-03-12T23:50:48.000+0000" }, { "id": "438673", "author": { "name": "bimmel-defective", "key": "bimmel", "displayName": "(deactived) Brian Immel", "active": false, "timeZone": "America/Los_Angeles" }, "body": "Note to [~bimmel]: Update https://wiki.appcelerator.org/display/guides2/Communication+Between+WebViews+and+Titanium#CommunicationBetweenWebViewsandTitanium-Remotewebcontent once this release has happened.", "updateAuthor": { "name": "bimmel-defective", "key": "bimmel", "displayName": "(deactived) Brian Immel", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2018-06-25T15:58:05.000+0000", "updated": "2018-06-25T15:58:05.000+0000" }, { "id": "442661", "author": { "name": "kmahalingam", "key": "kmahalingam", "displayName": "Keerthi Mahalingam", "active": false, "timeZone": "America/Los_Angeles" }, "body": "Waiting for resolving conflicts", "updateAuthor": { "name": "kmahalingam", "key": "kmahalingam", "displayName": "Keerthi Mahalingam", "active": false, "timeZone": "America/Los_Angeles" }, "created": "2018-10-16T18:31:09.000+0000", "updated": "2018-10-16T18:31:09.000+0000" }, { "id": "442924", "author": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "body": "I've confirmed that the async version of {{WebView.evalJS()}} does not have this problem, which is a new feature we've added in 7.5.0. See: [TIMOB-25862]", "updateAuthor": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2018-10-24T21:04:32.000+0000", "updated": "2018-10-24T21:04:32.000+0000" }, { "id": "442925", "author": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "body": "It is recommended that you use the async version of {{WebView.evalJS()}} instead.\r\nClosing as won't fix.", "updateAuthor": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2018-10-24T21:10:50.000+0000", "updated": "2018-10-24T21:10:50.000+0000" } ], "maxResults": 5, "total": 5, "startAt": 0 } } }