You can actually receive the console messages from a WebView, which would allow you to catch the errors that it throws.
To do so:
- Enable JavaScript on your WebView
- Set a WebChromeClient
- Override onConsoleMessage
Example:
final WebView webView = (WebView) findViewById(R.id.webview_terms_conditions);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.setWebChromeClient(new WebChromeClient() {
@Override
public boolean onConsoleMessage(ConsoleMessage consoleMessage) {
Log.d("MyApplication", consoleMessage.message() + " -- From line "
+ consoleMessage.lineNumber() + " of "
+ consoleMessage.sourceId());
return super.onConsoleMessage(consoleMessage);
}
});
webView.loadUrl(getString(R.string.url_terms_conditions));
Similar to what it says here, though that doc isn't complete and it uses a deprecated method.
When running on Android KitKat, you can also enable remote debugging!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…