Cancel navigation before executing 'beforeunload' in JS

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

Cancel navigation before executing 'beforeunload' in JS

Postby jvandenbossche » Fri Sep 15, 2023 5:16 am

According to the chromium docs the first step for out of origin navigations is to call the current document's 'beforeunload' function. I am looking for a way to cancel a navigation before the 'beforeunload' callback is executed and any network request is sent.

So instead of this:
beforeunload -> Request -> ...
I am looking for this:
check if navigation is allowed -> beforeunload -> Request -> ...

The functions I found that interact with navigation are the following:
OnBeforeBrowse: This seems to be the canonical way to block a navigation, however this gets executed after 'beforeunload' and the network request
OnBeforeRequest: This should block the navigation if the request fails but the 'beforeunload' function is still called according to the chromium docs
onBeforeNavigate: This is an extension function, it seems to be called at the moment required but I did not find any guarantees stating that it gets called before 'beforeunload', there is also the additional problem of calling into CEF to run the blocking logic and how to stop the navigation

Is there any way to achieve what I am seeking? Does supporting these requirements require changes in the Chromium codebase by adding a callback that provides us with the required guarantees?
jvandenbossche
Newbie
 
Posts: 1
Joined: Fri Sep 15, 2023 3:53 am

Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 182 guests