New issue
Advanced search Search tips

Issue 637825 link

Starred by 3 users

Issue metadata

Status: WontFix
Owner: ----
Closed: Aug 2016
Components:
EstimatedDays: ----
NextAction: ----
OS: Android
Pri: 3
Type: ----



Sign in to add a comment

Javascript isn't executed within onJAlert callback after new Android System Webview updated

Reported by choik...@gmail.com, Aug 15 2016

Issue description

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");  

 
Components: Mobile>WebView

Comment 2 by boliu@chromium.org, Aug 18 2016

Labels: Needs-Feedback
what do you mean exactly by "can't be executed"? just nothing happens? does the app deadlock? do you have a test app to demonstrate the problem?

Also you are already in java code in onJsAlert, why would you use the javabridge to go back to js and then callback to java again? that seems like bad design

Comment 3 by choik...@gmail.com, Aug 18 2016

So before, when the view.loadUrl(javascript:(function(){CustomInterface.completeAction(document.head.innerHTML)})());  
was called then the webview tried to load that uri hence the javascript method from the "CustomInterface"  was called.

Well the reason I m doing it it is because I want to grab some content from the html as you can see from the parameter "document.head.innerHTML".

I finally found the solution. 
I just have to call result.confirm() and then the javascript cant executed as before

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


Just wondering if this change was a bug or a feature ?
 

Comment 4 by boliu@chromium.org, Aug 18 2016

Status: WontFix (was: Unconfirmed)
that sounds like an intentional change in m52 then: https://www.chromestatus.com/features/5683408571203584

why do you need to come back to java then? can't you just directly execute whatever js you need, and just call back to java through CustomInterface?

Comment 5 by choik...@gmail.com, Aug 19 2016

Well due to some limitation of the backend, when the alert appears I need to parse the html file for a value I need to save. as you can see from my example the parameter I pass to my javascript interface is "document.head.innerHTML". 

Comment 6 by torne@chromium.org, Aug 19 2016

I'd suggest not using JS alerts as a way to notify the java code about events, if that's what you're doing (it sounds like it?). Call a javascript interface, or use postMessage on newer OS versions, or something.

Chromium will no longer support the nested event loop required to continue to process JS code while waiting for a response to alert/confirm/prompt, and unfortunately we aren't going to be able to revert this. alert/confirm/prompt are terrible because of their synchronous behaviour - ideally all web content should stop using them entirely.

Sign in to add a comment