Page 1 of 1

error page if URL could not be loaded

Posted: Fri Mar 06, 2020 9:47 am
by Namue
I want to show an error page, if the url could not be loaded. By default the component shows an white page.

I have 2 cases:
  • The URL is valid, but can not be reached (e.g. server ist offline / error in spelling).
    • In Chrome Browser, there is an error page shown.
    • I solved this by using the TChromium.OnLoadError and call a TChromium.LoadString to show my own error page. This works.
  • The URL is invalid (e.g. the user added an number too much to the port by mistake - so that the maximum is exceeded)
    • In Chrome Browser, there is an redirect to the google search.
    • I found no solution to get an event for this case. Does anyone know a possibility?

Re: error page if URL could not be loaded

Posted: Fri Mar 06, 2020 9:58 am
by salvadordf
Hi,

You can use TChromium.OnLoadError for both situations.

Use the "errorCode" parameter to generate a custom HTML error page that you can load with TChromium.LoadString. errorCode can have these values :
https://github.com/salvadordf/CEF4Delph ... ts.pas#L66

You can also check the "failedUrl" parameter to see if there are any errors and call TChromium.LoadURL to redirect the browser to any website.

Re: error page if URL could not be loaded

Posted: Fri Mar 06, 2020 10:10 am
by Namue
I already tried the TChromium.OnLoadError for both cases.
The first case works fine.
In the second case the event is not called. I already set a breakpoint to TChromiumCore.doOnLoadError, but the code is not called.
Is there maybe an setting I have to do before?

Re: error page if URL could not be loaded

Posted: Fri Mar 06, 2020 11:19 am
by salvadordf
The CEF code seems to check that the URL is valid before navigating to that address but it doesn't trigger any event.

In this case you have to inspect the URL in TChromium.OnBeforeBrowse
https://magpcss.org/ceforum/apidocs3/pr ... bool,bool)

Re: error page if URL could not be loaded

Posted: Fri Mar 06, 2020 1:52 pm
by Namue
TChromium.OnBeforeBrowse is also not called, if the URL is invalid. :(

Re: error page if URL could not be loaded

Posted: Fri Mar 06, 2020 1:56 pm
by salvadordf
:oops:

...then the only thing we can do is to check the URL even before we call TChromium.LoadURL

Re: error page if URL could not be loaded

Posted: Fri Mar 06, 2020 3:20 pm
by Namue
Ok, I did so. Thanks for your help.