[TIMOB-3370] iOS: WebView: fires load event multiple times
GitHub Issue | n/a |
---|---|
Type | Bug |
Priority | High |
Status | Closed |
Resolution | Fixed |
Resolution Date | 2013-09-06T16:51:36.000+0000 |
Affected Version/s | n/a |
Fix Version/s | Release 3.1.0, 2013 Sprint 05 API, 2013 Sprint 18, 2013 Sprint 18 API, Release 3.2.0 |
Components | iOS |
Labels | api, event, load, module_webview, parity, qe-testadded, webview |
Reporter | timothyf |
Assignee | Sabil Rahim |
Created | 2011-04-15T03:43:23.000+0000 |
Updated | 2013-11-25T08:49:14.000+0000 |
Description
I am using the following code to listen for the load event of a WebView:
webView.addEventListener('load', function(evt) {
mapView.evalJS("alert('" + evt.url + "');");
});</code>
When running this in the iPhone simulator, the load event appears to be getting fired 10 times. This listener is triggered 10 times and thus I get 10 alert's that pop up after the WebView has loaded.
*Update: The original PR created a side effect of if the remote webpage loaded uses JavaScript to POST a form to itself (i.e. the same URL), the WebView load event never fires.*
Bug still occurs on both iPhone/iPad. Load event is fired twice. Does not occur on Android (load event fires once correctly). SDK: 1.8.2 githash=59b3a90s, 2.0.0.v20120314120250 Studio: 2.0.0.201203121914 OS: Snow Leopard Devices Tested: iPad 4.3.5, iPhone Simulator 5.0 Steps to Reproduce: 1. Run code, press 'Open Google'.
Expected Result: Only one load event should fire. Actual Result: Two load events fire.
I am seeing this same issue on iOS under 1.8.2. It appears to only happen under certain conditions though. Attempting to isolate those conditions, thinking it may be the result of DOM changes within the WebView content.
PR https://github.com/appcelerator/titanium_mobile/pull/3909
Tested with: SDK: 3.1.0.v20130313215655 Studio: 3.0.2.201302191606 Device: iPad2(v 5.1) OS: OSX 10.7.5 load event is fired only once as expected.
This created an equally bad side-effect. If the remote webpage loaded uses JavaScript to POST a form to itself (i.e. the same URL), the WebView load event never fires.
Looking at the PR, I'm guessing that any form of navigating back to the same URL probably will have the same issue.
[~vduggal] Can you please investigate?
Probably should check for navigationType in shouldStartLoad delegate method and clear out the history is nav type is anything other than UIWebViewNavigationTypeOther
I think that makes sense. The simplest test would be to create a HTML form that posts to itself. The next step up would be a link that uses javascript to reload a page.
Marked as resolved fixed, but without any additional code changes or tickets? I think this one slipped past QA.
It appears we didn't resolve the secondary issue brought up later. Reopening and scheduling for 3.2.0
Issue occurs on the following environment: SDK: 3.1.2.v20130809141556 Appcelertaor Studio: 3.1.2.201308091728 OS: OSX 10.8.4 Device: iPhone5(v 6.1.4) Xcode: 4.6.3
Wait, how could this possibly have been fixed without any code changes?
Is there any workaround to the secondary problem that Shannon brought up? Any method of the webview that I can call to "reset" things so that the load event will refire when the javascript reloads the same page? I'm using 3.1.2.GA.
Tested With: OSX: 10.8.5 Xcode:5.0 Appcelerator Studio: 3.2.0.201310112258 SDK:3.2.0.v20131014204636 acs:1.0.7 alloy:1.2.2 npm:1.3.2 titanium:3.2.0 titanium-code-processo:1.0.3 Device: iPod touch2 (viOS7)
[~bitshftr] Following up here. Did a second ticket get created for the additional problem you were inquiring about?
Ingo, are you talking about this: "If the remote webpage loaded uses JavaScript to POST a form to itself (i.e. the same URL), the WebView load event never fires." ? If so, then no, I was assuming that this was part of the 3.2.0 fix for this ticket. Otherwise, please remind me what the "additional problem" was.
Anvil test case added. PR link: https://github.com/appcelerator/titanium_mobile/pull/5020