0

I have a webview and the javascript interface is also there. How can I add a window.onerror for it? The main requirement is that when I load the webview with content the otf files are throwing some invalid tag error ("OTS parsing error: invalid version tag") and I need to capture that error.

Midhun Kumar
  • 549
  • 5
  • 23

1 Answers1

0

You can call a JavaScript function from Java when you get the error:

/**
 * Executes received Java Script call
 *
 * @param command - JS call to run
 */
protected void executeJsCommand(final String command) {
        webView.evaluateJavascript(command, new ValueCallback<String>() {
            @Override
            public void onReceiveValue(final String value) {}
        });
}

protected void callOnError(String error) {
    executeJsCommand("window.onerror( " + error +" )");
}
Doron Yakovlev Golani
  • 5,188
  • 9
  • 36
  • 60
  • We don't know at what point exactly the error gets thrown. So for handling it we first need to know when the error gets thrown and for that, we have to catch such an error first. And how can I do that? – Midhun Kumar May 12 '17 at 05:25
  • I found a link where it says we can override console.warn but am not able to get any of the warnings inside the function which was used to replace the warn. – Midhun Kumar May 12 '17 at 11:58