Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to catch Web console errors?

Using WebView, certain websites take very long time to complete page load (as in WebViewClient.onPageFinished()) and, when that happens, this is characterize by Web Console errors of the following type:

E/Web Console(1916): Unsafe JavaScript attempt to access frame with URL
  http://mobile.example.com from frame with URL 
  http://ad.doubleclick.net/adi/interactive.example.com/front_sub;sz=320x50;ord=7340930261983.
  Domains, protocols and ports must match.
  05-26 10:44:15.274: E/Web Console(1916):  at null:1

I would like to be able to catch those errors and handle them in some way. e.g. issue a message or anything relevant to my app, actual handling is irrelevant at this point to the core question:

Is there a way to catch those errors? i.e. in a way that my app can be notified?

Note: This is not a Javascript question. I am not programming a website. I am accessing an existing website whose implementation is beyond my control. This is a WebView question (currently in the Android environment, but could be in other environments which are capable of hosting WebView as well).

like image 585
scatmoi Avatar asked May 26 '13 14:05

scatmoi


1 Answers

Do you have an example of a website?

You should be able to override WebChromeClient.onConsoleMessage(ConsoleMessage consoleMessage).

like image 149
Kristian Avatar answered Oct 28 '22 06:10

Kristian