2

I need to catch an error when invoking javascript from android's webview; if the javascript is missing I need to catch some event and do something else in android instead.

for instance, I have webview.loadUrl("javascript:doSomething");

the page is missing 'doSomething', so I can see the following error in logcat:

ReferenceError: Can't find variable: doSomething ...

I need to catch this error and handle it, for instance something like

public override void onJsErrorReceived(String errorDescription)
{
    if(errorDescription.contains("doSomething"))
       handleError();
}

I can't find any such event in webview, nor in the clients of webview (WebChromeClient and WebViewClient) to overridel.

Does anybody have an idea?

Thanks

1 Answer 1

0

As per this question, the methods you need to over-ride are:

WebChromeClient.onConsoleMessage(String message, int lineNumber, String sourceID)

and

WebChromeClient.onConsoleMessage(ConsoleMessage cm),

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.