From 66cda41bfc2f3b12c18b7f09bda35f90db1a9b0b Mon Sep 17 00:00:00 2001 From: daboe01 Date: Mon, 28 Sep 2026 15:46:35 +0200 Subject: [PATCH] fixed: terminate on pagehide instead of unload instead of unload --- AppKit/Platform/DOM/CPPlatform.j | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/AppKit/Platform/DOM/CPPlatform.j b/AppKit/Platform/DOM/CPPlatform.j index 63d04a0fd..39c2b8a41 100644 --- a/AppKit/Platform/DOM/CPPlatform.j +++ b/AppKit/Platform/DOM/CPPlatform.j @@ -57,11 +57,25 @@ var screenNeedsInitialization = NO, return [CPApp _sendDelegateApplicationShouldTerminateMessage]; }; - window.onunload = function() + var terminateApplication = function() { [self closeAllPlatformWindows]; [CPApp terminate:nil]; }; + + // "unload" is blocked by the permissions policy in current Chrome and prevents the + // back/forward cache. "pagehide" fires reliably instead. If event.persisted is true the + // page goes into the bfcache and may be restored, so the application must not terminate. + if ("onpagehide" in window) + { + window.addEventListener("pagehide", function(anEvent) + { + if (!anEvent.persisted) + terminateApplication(); + }, NO); + } + else + window.onunload = terminateApplication; } }