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

baruch dego
  • 101
  • 1
  • 6

1 Answers1

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),

Community
  • 1
  • 1
Maks
  • 7,562
  • 6
  • 43
  • 65