Titanium JIRA Archive
Appcelerator Community (AC)

[AC-5286] App crashes when executing evalJS in a webview to change its contents (Ti SDK 6 and Android 4.1.1 only)

GitHub Issuen/a
TypeBug
Priorityn/a
StatusResolved
ResolutionDone
Resolution Date2017-12-18T21:12:50.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsTitanium SDK & CLI
Labelsn/a
ReporterDavid Benko
AssigneeShak Hossain
Created2017-10-16T19:57:15.000+0000
Updated2017-12-18T21:12:50.000+0000

Description

I have a webview that I use evalJS to call a function inside it that changes the content of its html. The app will crash when the javascript inside the webview try to add a paragraph to the html for example. This bug is only happening on Android 4.1.1. I tried the following SDKs: 6.1.2, 6.2.2 and SDK 6.3.0.v20171016053946 and the bug is happening in all of them. The line that causes the app to crash is the following line inside the webview:
div.appendChild(paragraph);
Another way to change the content would simply be:
div.innerHTML = '<p>' + text + '</p>'
But this causes crash too. I also tried to replace evalJS usage with Ti.App.fireEvent and calling SetTextContent inside Ti.App.addEventListener on the webview but the bug still happens. Code to reproduce:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
	<div id="content"></div>
	<script>
		function SetTextContent(text) {
			var div = document.getElementById("content");
			var paragraph = document.createElement('p');
			var textNode = document.createTextNode(text);
			paragraph.appendChild(textNode);
			if (div.hasChildNodes()) {
				div.removeChild(div.childNodes[0]);
			}
			div.appendChild(paragraph); // This line causes the app to crash. If you comment this line everything works fine.
		}
	</script>
</body>
</html>
var window = Ti.UI.createWindow();
var webView = Ti.UI.createWebView({
	url: '/test.html'
});
window.add(webView);

window.open();

setInterval(function() {
	webView.evalJS('SetTextContent(\'testing' + Math.random() + '\')');
}, 3000);

Comments

  1. David Benko 2017-10-18

    Can anyone verify this issue please?
  2. Sharif AbuDarda 2017-11-12

    Hello, Is this only happening on Android 4.1.1? I tried on a different version. wasn't able to reproduce. Can you try on the latest SDK 6.3.0.GA? Thanks.
  3. Mostafizur Rahman 2017-11-20

    Hello [~davidbenko], I just wanted to follow up here. Did you manage to follow the instructions provided earlier? Let us know if you still experience any issue. We would be happy to assist you. Best Regards!
  4. David Benko 2017-11-20

    Hello, the test case I provided is now indeed working in SDK 6.3.0. However, the webview is still crashing the app with other use cases. I'll try to provide a new code to reproduce.
  5. Mostafizur Rahman 2017-11-21

    [~davidbenko] Thanks for your feedback. We will be waiting for your new test code. Best
  6. Mostafizur Rahman 2017-11-30

    Hello [~davidbenko],
 Just passing a followup here.Are you able to get that sorted out?  Please let us know if you need more help with this issue. Regards
 Axway Appcelerator Support
  7. Mostafizur Rahman 2017-12-04

    Hello [~davidbenko], Are you still having the issue?Please let us know if you need more help with this issue. Regards
 Axway Appcelerator Support
  8. David Benko 2017-12-04

    Hello, thanks for getting back to me. I'm working on provide an example to reproduce the issue. My app is large and does a buch of interactions with the webview, so I'm trying reducing the problem to a reproducible test case
  9. Mostafizur Rahman 2017-12-05

    [~davidbenko],Ok. Thanks for your update. We appreciate it. We will be waiting for your reproducible test case. Best
  10. Mostafizur Rahman 2017-12-17

    Hello [~davidbenko], Did you manage to generate the reproducible test case?
  11. David Benko 2017-12-18

    Hello Mostafizur, I'm having a hard time trying to reduce to a small test case because the app is large. Anyways we already solved the issue by changing some things in our app so the bug is not happening anymore. You can close the issue

JSON Source