Disclosure Statement: This site contains affiliate links, which means that I may receive a commission if you make a purchase using these links. As an eBay Partner, I earn from qualifying purchases.

error page if URL could not be loaded

Post Reply
User avatar
Namue
Posts: 4
Joined: Fri Mar 06, 2020 6:55 am

error page if URL could not be loaded

Post 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?
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: error page if URL could not be loaded

Post 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.
User avatar
Namue
Posts: 4
Joined: Fri Mar 06, 2020 6:55 am

Re: error page if URL could not be loaded

Post 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?
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: error page if URL could not be loaded

Post 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)
User avatar
Namue
Posts: 4
Joined: Fri Mar 06, 2020 6:55 am

Re: error page if URL could not be loaded

Post by Namue »

TChromium.OnBeforeBrowse is also not called, if the URL is invalid. :(
User avatar
salvadordf
Posts: 4016
Joined: Thu Feb 02, 2017 12:24 pm
Location: Spain
Contact:

Re: error page if URL could not be loaded

Post by salvadordf »

:oops:

...then the only thing we can do is to check the URL even before we call TChromium.LoadURL
User avatar
Namue
Posts: 4
Joined: Fri Mar 06, 2020 6:55 am

Re: error page if URL could not be loaded

Post by Namue »

Ok, I did so. Thanks for your help.
Post Reply