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?