1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-10 23:44:24 +00:00

Windows: WebBrowserComponent: Avoid infinite loops caused by CONNECTION_ABORTED errors

WebView2 can emit COREWEBVIEW2_WEB_ERROR_STATUS_CONNECTION_ABORTED
errors during page navigation, even if the page navigation would happen
correctly afterwards. In such situations our internal error handler can
recursively encounter this error when trying to navigate to the error
handler page.

Prior to this commit the implementation could end up in an infinite loop
receiving the error and then navigating to the error handler page.
This commit is contained in:
attila 2024-09-19 17:37:27 +02:00
parent c545ca0492
commit 46eed81aae
2 changed files with 26 additions and 1 deletions

View file

@ -606,6 +606,9 @@ public:
The errorInfo contains some platform dependent string describing the
error.
Calling goToURL() inside this callback can encounter further network
errors, potentially causing an infinite loop.
*/
virtual bool pageLoadHadNetworkError (const String& errorInfo);

View file

@ -806,7 +806,29 @@ private:
auto errorString = "Error code: " + String (errorStatus);
if (owner.pageLoadHadNetworkError (errorString))
owner.goToURL ("data:text/plain;charset=UTF-8," + errorString);
{
const auto adhocErrorPageUrl = "data:text/plain;charset=UTF-8," + errorString;
if (owner.lastURL == adhocErrorPageUrl)
{
// We encountered an error while trying to navigate to the adhoc
// error page. Trying to navigate to the error page again would
// likely end us up in an infinite error callback loop, so we
// early exit.
//
// Override WebBrowserComponent::pageLoadHadNetworkError and
// return false to avoid such a loop, while still being able to
// take action on the error if necessary.
//
// Receiving Error code: 9 can often be ignored safely with the
// current WebView2 implementation.
jassertfalse;
return S_OK;
}
owner.goToURL (adhocErrorPageUrl);
}
}
}