Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-17613] Unable to execute javascript code using evalJS on Android with SDK 3.3.0.GA

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2014-09-15T17:37:10.000+0000
Affected Version/sn/a
Fix Version/sRelease 3.4.0
ComponentsAndroid
Labels3.3.0, Android, Titanium, evalJS, module_android, qe-testadded
ReporterIvo
AssigneeHieu Pham
Created2014-09-03T15:57:15.000+0000
Updated2014-11-20T15:50:52.000+0000

Description

Attachments

FileDateSize
Screen Shot 2014-09-03 at 5.08.00 PM.png2014-09-03T15:57:16.000+0000236063

Comments

  1. Urban Gerber 2014-09-04

    We have this issue in our enterprise app, relying on evaluating js functions embedded in remote html pages rendered in a WebView. We use this as kind of event mechanism, for the app to take control on certain user actions done on the remote web site. I have tested Ivo's sample on a real device, Samsung Galaxy Note 10.1. Works on SDK 3.2.3, does not work on SDK 3.3.0! This is a blocking issue for us, cannot upgrade the SDK. Please fix in the next SDK. Thanks
  2. Ingo Muschenetz 2014-09-04

    From TIMOB-15896, is it possible for you to try adding the annotation and see if that fixes the issue for you? It would require you to build a custom SDK, but it would help speed up resolution.
  3. Ivo 2014-09-05

    After doing some investigation on the changes done on this file https://github.com/appcelerator/titanium_mobile/blob/3_3_X/android/modules/ui/src/java/ti/modules/titanium/ui/widget/webview/TiWebViewBinding.java#L153 We believe that we have located the problem, which according us is not related to missing annotation in the code (note that annotation is already present, and according to the Android documentation this has effect only on API >= 17). Instead, we think that the problem is introduced by newly added code, which does some pattern matching before evaluating the Javascript expression. The conslusion was made by comparing the same file from 3.2.X and 3.3.X (copy the contents of both files in some diff tool). After reverting this code, and building the Titanium SDK from scratch, it seems that the issue is resolved. However, we believe that this code was put there for some reason, thus removing it is not the best idea. We would be very gratefull if you fix the problem with the pattern/matcher and provide the fix in the next SDK release.
  4. Ingo Muschenetz 2014-09-05

    Thank you! That's very helpful.
  5. Ingo Muschenetz 2014-09-05

    The original test case (from TIMOB-10837):
       webView.addEventListener('load', function() {
           webView.evalJS('var a="test";document.body.innerHTML=a'); // doesn't works
           //webView.evalJS('document.body.innerHTML="test"'); // works
       });
       
    Seems we need to add a few more cases to make sure we evaluate them correctly. I'm assuming we can simplify the example above. Is it just because it's a self-invoking function?
  6. Ingo Muschenetz 2014-09-05

    Marking as for 3.4.0 unless we come up with a suitable workaround.
  7. Hieu Pham 2014-09-07

    master PR: https://github.com/appcelerator/titanium_mobile/pull/6026 3.4.X PR: https://github.com/appcelerator/titanium_mobile/pull/6027
  8. Lokesh Choudhary 2014-09-12

    Verified the fix. After running the code in the description we now get :
       [INFO] :   ALERT: (KrollRuntimeThread) [456,456] {f1:1,f2:2}}
       
    which is expected behaviour & shows the execution of javascript code using evalJS. Closing. Environment: Appc Studio : 3.4.0.201409112242 Ti SDK : 3.4.0.v20140912084114 Mac OSX : 10.9.4 Alloy : 1.5.0-rc CLI - 3.4.0-rc2 Code Processor: 1.1.1 Genymotion Emulator - android 4.1.1
  9. grebulon 2014-11-20

    This happens again on 3.4.1GA on Lollipop. On Android 4.4.2 it's all fine.
  10. grebulon 2014-11-20

    Please ignore my previous comment. It was premature.

JSON Source