SINKING/SUPPRESSING WEBVIEW ERRORS

171 views
Skip to first unread message

Chinedu Emeka

unread,
May 4, 2020, 8:20:07 AM5/4/20
to DroidScript
Hello,
I have developed an app that relies heavily on webview. My question is this, let us say that a nonexistent URL such as web.LoadUrl( "http:///www.xxsunty.com" );  is entered, the webview shows "web page not available .....net::ERR_NAME_NOT_RESOLVED
I would prefer to intercept and suppress this error message and load a local page with
web.LoadHtml( html,) that shows a more a pleasant message such as ..... please check the url you entered and try again.

I have used   web.SetOnError(web_error) and been able to load a new page in my web_error function but this only shows after the error has shown. is there anyway to sink/suppress the original error?

Thank you

Chinedu

Dirk Wilson

unread,
May 4, 2020, 9:29:22 AM5/4/20
to DroidScript
You could try accessing the url with AJAX (or another api) first to see that its it's reachable.

Steve Garman

unread,
May 4, 2020, 9:30:57 AM5/4/20
to DroidScript
web.LoadHtml responds immediately for me without displaying the error page first.

function web_OnError()
{
web.LoadHtml(app.ReadFile("err.html"));
}

Chinedu Emeka

unread,
May 4, 2020, 11:04:00 AM5/4/20
to DroidScript
it worked, thank you.

Dave

unread,
May 5, 2020, 12:54:32 PM5/5/20
to DroidScript
You might be pleased to here that I have just added a new method to the WebView control that redirects it immediately to a given local web page when a page loading error occurs:-

web.SetErrorPage( "error.html" );


This avoids the short flash of the error that you can get when using the OnError callback to redirect.

(Available in the the next beta release 183b3 comming in the next few days)

Kallikratidas

unread,
May 5, 2020, 5:14:00 PM5/5/20
to DroidScript
Can you please include a function to get the WebView status?
404, 403 etc.

Dave

unread,
May 6, 2020, 5:45:25 AM5/6/20
to DroidScript
The error code is passed to the error handling page in the url  (so you can extract it using the document.location property)

Chinedu Emeka

unread,
May 6, 2020, 3:45:42 PM5/6/20
to DroidScript
Great! I will tarry a bit for it.

Chinedu Emeka

unread,
May 8, 2020, 5:46:10 AM5/8/20
to DroidScript
Hello,

I seem to have hit another snag. When I was using "IgnoreErrors" option of webview, my app was ignoring "Unrecognized feature: 'picture-in-picture'." caused by playing a youtube video through an iframe in webview. In this case, I really want to ignore the error.
Now that I am using web.SetOnError(web_error); execution is being diverted to my local page instead of playing my youtube video.
Is there anyway to catch some errors i.e 404 while allowing other errors such as youtube picture in picture .

thank you,
Chinedu

Chinedu Emeka

unread,
May 8, 2020, 7:58:12 AM5/8/20
to DroidScript
Hello,
The first solution I have found is just to ignore the error when it gets into the procedure setup to handle the webiew errors.

Thank you
Reply all
Reply to author
Forward
0 new messages