0

|After the latest updated of the Android System Webview (52.0.2743.98) I noticed that javascript can't be executed withing the onJsAlert method.

More specifically the following piece of code stopped working after the latest update

private class MyWebChromeClient extends WebChromeClient {

    @Override
    public boolean onJsAlert(WebView view, String url, String message, JsResult result) {

            view.loadUrl(javascript:(function(){CustomInterface.completeAction(document.head.innerHTML)})());

        return super.onJsAlert(view, url, message, result);
    }

}

I have also checked that the interface has been set correctly

  mWebView.setWebChromeClient(new MyWebChromeClient());

    WebSettings webSettings = mWebView.getSettings();      
    webSettings.setJavaScriptEnabled(true);
    mWebView.addJavascriptInterface(new CustomInterface(), "CustomInterface"); 

Has anyone came across the same issue?

Chris
  • 1,641
  • 1
  • 16
  • 17

1 Answers1

0

Th hint for the solution was given to me when I returned false for the onJAlert

 @Override 
    public boolean onJsAlert(WebView view, String url, String message, JsResult result) {

            view.loadUrl(javascript:(function(){CustomInterface.completeAction(document.head.innerHTML)})());

        return false;
    } 

If the client returns true, WebView will assume that the client will handle the dialog. If the client returns false, it will continue execution. So by returning false I got a dialog box on my UI and when I pressed ok the javascript was executed. So I just called confirm from the JsResult which was like pressing the OK button

   @Override 
    public boolean onJsAlert(WebView view, String url, String message, JsResult result) {
            result.confirm();
            view.loadUrl(javascript:(function(){CustomInterface.completeAction(document.head.innerHTML)})());

        return true;
    } 
Chris
  • 1,641
  • 1
  • 16
  • 17