The Page Visibility API is supposed to trigger a visibilitychange event (MDN) when the user leaves a webpage (i.e. user changes tab, closes tab, OS or user close the app ...).
This works fine in Safari and Chrome on macOS (and should also work for firefox, although I could not test right now). But in Orion the event fires only on hide/unhide, but not when the tab is closed. Maybe there is some over-zealous resource freeing routine on tab close at work here?
This can be easily reproduced using this simple HTML page and python3 -m http.server
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<link rel="icon" href="data:;base64,=">
</head>
<body>
<script>
document.onvisibilitychange = () => {
if (document.visibilityState === "hidden") {
navigator.sendBeacon("/log", {});
}
};
</script>
</body>
</html>
You should see request to the /log endpoint in python's output when navigating to http://localhost:8000 and then hiding or closing (when not using Orion) the tab.
I have also attached a video demonstrating this in Safari and Orion (new empty profile). What you can see in the video is
- I am opening and switching the tab in Orion, the POST request shows up in the console ✅
- I am opening and switching the tab in Safari, the POST request shows up in the console ✅
- I am opening then closing the tab in Orion, no POST request ❌
- I am opening then closing the tab in Safari, the POST request shows up in the console ✅
The Page Visibility API is supposed to trigger a visibilitychange event (MDN) when the user leaves a webpage (i.e. user changes tab, closes tab, OS or user close the app ...). Togehter with Beacon API's sendbeacon method (MDN) this is now the recommended way to send data when a user leaves your page according to MDN. Other methods such as using unload or beforeunload events are discouraged (e.g. because of cache considerations).
An internal app we are using is heavily dependent on this to update session/presence states when a user leaves the page and I am receiving complaints about this (some of my colleagues are big kagi/Orion fans). Tracing down this issue was somewhat complicated by the fact that the official OpenTelemtry tracing sdk also seems to depend on this functionality to flush traces when a page is closed. I could imagine that this also affects other instrumentation and development tools.
This alos affects compatibility mode.
Version 0.99.126.4.1-beta (WebKit 618.1.2)
Sonoma (14)