Uploaded image for project: 'Appcelerator - INBOX'
  1. Appcelerator - INBOX
  2. AC-1157

WebView.evalJS times out / throws 'Unexpected token' error

    Details

      Description

      When executing some javascript via evalJS on a WebView nothing happens and this error appears in the console:

      [INFO] :   I/TiWebChromeClient.console: (main) [255,24655] Uncaught SyntaxError: Unexpected token for (1:file:///data/data/com.ortec.synergy/cache/86/platform_article_135660018/article.html)
      [WARN] :   TiWebViewBinding: (KrollRuntimeThread) [3245,27900] Timeout waiting to evaluate JS
      

      To reproduce:

      var win = Ti.UI.createWindow({
      	backgroundColor:'white'
      });
       
      var webView = Ti.UI.createWebView({
      	html:'<html><head></head><body><p><a href="Yoyo">Hello</a></p></body></html>'
      });
       
      webView.addEventListener('load', function( e ) {
      	// replace all a-href with javascript links to capture in Titanium
      	webView.evalJS('(function(){var h,a=document.getElementsByTagName("a");for(var i=0,l=a.length;i<l;i++){h=a[i].attributes["href"];if(h && h.value && !String(h.value).match(/^#/) && String(h.value).indexOf("javascript:") === -1){h.value="javascript:Ti.App.fireEvent(\'linkClicked\',{href:\'"+h.value+"\'})"}}})();');
      });
       
      Ti.App.addEventListener('linkClicked', function( e ) {
      	alert(e.href);
      });
       
      win.add(webView);
      win.open();
      

      The code works fine on iOS. The issue might be the same as TIMOB-15896.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                sliang Shuo Liang
                Reporter:
                gertjans Gertjan Smits
              • Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Git Source Code