Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-10837

Android: webView throws on evalJS when string starts with `var`

    Details

      Description

      Problem

      When trying to evalJS a string with code that starts with `var` it doesn't work and I get this error message in Console:

      [INFO][TiWebChromeClient.console( 1229)] (main) [493,23278] Uncaught SyntaxError: Unexpected token var (1:http://www.google.com/)
      

      Expected Behavior

      Should not throw and instead replace the site contents with "test". Works on iOS.

      Test case

      app.js

      var win = Ti.UI.createWindow();
       
      var webView = Ti.UI.createWebView({
      	url: 'http://google.com',
      	top: 0,
      	bottom: 0,
      	height: Ti.UI.FILL,
      });
       
      win.add(webView);
       
      win.open({
           modal: true,
           animated: false
      });
       
      webView.addEventListener('load', function() {
      	webView.evalJS('var a="test";document.body.innerHTML=a'); // doesn't works
      	//webView.evalJS('document.body.innerHTML="test"'); // works
      });
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                mofle Sindre Sorhus
                Reviewer:
                Hieu Pham
              • Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:

                  Backbone Issue Sync

                  • Titanium SDK/CLI <> Titanium Mobile
                    Synced with:
                    TIMOB-14196
                    Sync status:
                    ERROR
                    Last received:
                    Last sent:

                    Git Source Code