Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-25387] Android Ti.App.addEventListener not working when there is an iframe in local html file

GitHub Issuen/a
TypeBug
PriorityNone
StatusOpen
ResolutionUnresolved
Affected Version/sRelease 6.2.2
Fix Version/sn/a
ComponentsAndroid
Labelsn/a
ReporterAnthony Chung
AssigneeUnknown
Created2017-10-04T05:54:50.000+0000
Updated2018-02-28T19:55:28.000+0000

Description

Test case provided here... Environment, android, Ti. 6.1.1.GA plus. [https://github.com/anthonychung/jira-appcelerator-tests/tree/issues/test-android-iframe-fireevent]

Android Ti.addEventListener not working when there is an iframe in local html file

<script>
Ti.App.addEventListener("app:fromTitanium", function(e) {
	alert(e.message);
});
</script>
This will work when local html has no iframe. When there is an iframe in android local html content, Ti.addEventListener no longer works.

On iOS This works fine.

But on Android, having an iframe disables the functionality of the inline javascript Ti.App.addEventListener

To test

- run the app in Android, then click "Test without iframe" button, which will load index-noiframe.html with the eventListener, click "Fire Event" and the event will successfully alert. - close window, then click "Test with iframe" button, which will load index-noiframe.html with the eventListener, click "Fire Event" and the event will not work.

Comments

  1. Anthony Chung 2017-10-06

    This issue appears to be related to Android webview overwrites the jscontext for the parent, with the child's jscontext. Whereas, on ios, it preserves the parent jscontext. And since the Ti.App.addEventListener is a part of the parent's context (I assume it is injected with __ti_injection into the parent and not the child). Then ios handles the support for this correctly. But Android is wiping out the parent web application. This is a critical issue for our application, because the American DOD ADL SCORM standard requires that the parent iframe expose apis for the child eLearning SCORM packages to talk to. Other frameworks seem to have faced this problem. https://stackoverflow.com/questions/9050949/webview-on-android-ics-iframe-problems-with-android-assets/10210172#10210172 Part of it is android webview, but another is that it affects the function of the Ti.App.addEventListeners. [~hknoechel] Have appc clients come across this issue before and is there are workaround? I will follow up also follow up with your official chat/support channel. Any advice related to this issue would be appreciated.
  2. Motiur Rahman 2017-10-13

    Hello! I tested the issue and reproduce it with the following environment Ti SDK: 6.2.2.GA, 6.1.2.GA Android Emulator: 7,6 Android Device: v4.4.2 Steps To Reproduce 1. Run the following code 2. Click the button "From Titanium", (event is not firing, this is the issue) 3. If you remove the iframe from the html code then it works again.
       var win = Ti.UI.createWindow();
       	var webview = Ti.UI.createWebView({
       		url : '/index-withiframe.html'
       	});
       	var button = Ti.UI.createButton({
       		title : 'fromTitanium',
       		height : '50dp',
       		width : '130dp'
       	});
       	button.addEventListener('click', function(e) {
       		Ti.App.fireEvent('app:fromTitanium', {
       			message : 'event fired from Titanium, handled in WebView'
       		});
       	});
       	Ti.App.addEventListener('app:fromWebView', function(e) {
       		alert(e.message);
       	});
       
       	win.add(webview);
       	win.add(button);
       	win.open();
       
       
       <html>
       	<head>
       		<script>
       			Ti.App.addEventListener("app:fromTitanium", function(e) {
       	        	alert(e.message);
       	      	});
       		</script>
       	</head>
       	<body>
       		
       	<iframe src="blank.html"></iframe> 
       	
       	</body>
       </html>
       
       <html>
       	<head>
       		
       	</head>
       	<body>
       		<button onclick="Ti.App.fireEvent('app:fromWebView', { message: 'event fired from WebView, handled in Titanium' });">fromWebView</button>
       	</body>
       </html>
       
    Thanks
  3. Anthony Chung 2017-10-17

    Hi, is there any news on this issue? I have been running extra tests. In Android, the load event fires twice. This could be causing issues for the ti_injection. When I set up listeners on the child. Then it works. But I need the listeners on the parent. Android has a different event called onPageStarted that is fired when an iframe page is loaded, this can help distinguish from the double load event. If the ti_injection code needs to be adapted, the injection needs to happen on the parent and not the child load event. Checking the local html code for the presence of 'iframe' on android can help to avoid doing the injection on the second load event and if something needs to be performed when everything is loaded then we can look for onPageStared on Android. https://developer.android.com/reference/android/webkit/WebViewClient.html#onPageStarted(android.webkit.WebView, java.lang.String, android.graphics.Bitmap)
  4. Anthony Chung 2017-10-17

    [~hknoechel] any chance of getting your perspective on this issue?

JSON Source