Page 1 of 1

Back Issue OnLoadError rendering with LoadUrl best approach?

PostPosted: Mon Dec 09, 2019 11:51 am
by mitchc
With recent changes using LoadString for error handling was ruled a bad idea:
https://bitbucket.org/chromiumembedded/ ... ce-and-get
https://bitbucket.org/chromiumembedded/ ... imple-when
https://bitbucket.org/chromiumembedded/ ... -makes-the

and was removed in newer commits all together.

LoadUrl with a base64 encoded error message seemed like a good stop gap for displaying OnLoadError messages to the user.

The problem with this is is LoadUrl adds a new navigation entry to history as well. When this is mixed with the fact there is only GoBack/GoForward short of walking the history tree then manually navigating back to the entry from two before there is not a great way to support the back button properly.

Currently assuming a non temporal error OnLoadError is called when visiting errorsite.com this then leads to LoadUrl being called with the error message causing bath in the history stack. Hitting back navigates again to errorsite.com which immediately would cause OnLoadError to trigger resulting in the user being stuck.

A work around is to detect on an error page and inject javascript of history.go(-2) on back request which works but is clumsy to a degree.

The cleanest options would seem:
1) Rendering an error page outside of the browser itself
2) On option to not add (or to remove) entries from the navigation history, so back works as expected
3) To intercept the error earlier in the chain and return custom text for the page as is bypassing OnLoadError.

Re: Back Issue OnLoadError rendering with LoadUrl best appro

PostPosted: Mon Dec 09, 2019 12:39 pm
by mitchc
The LoadUrl is used by the sample client for example:
https://bitbucket.org/chromiumembedded/ ... ler.cc-149

so it is subject to the same issue (browser to a invalid domain for example and try to go back).

Re: Back Issue OnLoadError rendering with LoadUrl best appro

PostPosted: Mon Dec 09, 2019 1:06 pm
by magreenblatt
You raise valid points. See the comment at https://bitbucket.org/chromiumembedded/ ... t-52020179

Re: Back Issue OnLoadError rendering with LoadUrl best appro

PostPosted: Fri Jan 26, 2024 9:58 am
by aleitner
I am also encountering this exact same issue at the moment with my application. Is there a way to either delete a navigation entry or prevent a navigation entry from being added to history? I am unable to see the comment at the url mentioned below.

magreenblatt wrote:You raise valid points. See the comment at https://bitbucket.org/chromiumembedded/ ... t-52020179

Re: Back Issue OnLoadError rendering with LoadUrl best appro

PostPosted: Fri Jan 26, 2024 10:30 am
by magreenblatt
The updated issue URL is https://github.com/chromiumembedded/cef/issues/2586. I’m not sure which specific comment was linked at the time.

Re: Back Issue OnLoadError rendering with LoadUrl best appro

PostPosted: Fri Jan 26, 2024 10:33 am
by magreenblatt
Is there a way to either delete a navigation entry or prevent a navigation entry from being added to history?

It may be possible via JavaScript, see https://stackoverflow.com/questions/200 ... 0#20044710

Re: Back Issue OnLoadError rendering with LoadUrl best appro

PostPosted: Fri Jan 26, 2024 3:36 pm
by amaitland

Re: Back Issue OnLoadError rendering with LoadUrl best appro

PostPosted: Tue Jan 30, 2024 10:32 am
by aleitner
amaitland wrote:Try DevTools Page.setDocumntContent to load content without performing a navigation.

https://chromedevtools.github.io/devtoo ... entContent

You can look at https://github.com/cefsharp/CefSharp/blob/bbe7260fe8d0fa4507cf0e36dea36ffe63b35f91/CefSharp.WinForms.Example/BrowserTabUserControl.cs#L232 for some inspiration.


Does the libcef capi also provide the ability to invoke setDocumentContent?

Re: Back Issue OnLoadError rendering with LoadUrl best appro

PostPosted: Tue Jan 30, 2024 10:09 pm
by aleitner
Until I can figure out a way to use Page.setDocumentContent, I'm just manually writing the html to the document using execute_java_script.

Code: Select all
"document.open();"
"document.write('<html>Uh oh... I errored......</html>);"
"document.close();

Re: Back Issue OnLoadError rendering with LoadUrl best appro

PostPosted: Sat Feb 10, 2024 8:35 pm
by amaitland