Commit 229a5e2c authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇

Signal player gone in "pagehide" not "beforeunload"

I don't recall if there was a particular reason for using *before* unload but this event is not emitted for iframes.
Using "pagehide" instead makes an iframe content script notice it's being destroyed (e.g. because of the overlay it was in being removed)
and correctly signals the player being gone. "unload" supposedly causes the browser trouble caching the page.
We did noticed a video in an overlay being removed but not when it was inside of an iframe.

Differential Revision:
parent a39beb6c
......@@ -607,10 +607,11 @@ function loadMpris() {
subtree: true
window.addEventListener("beforeunload", function () {
window.addEventListener("pagehide", function () {
// about to navigate to a different page, tell our extension that the player will be gone shortly
// we listen for tab closed in the extension but we don't for navigating away as URL change doesn't
// neccesarily mean a navigation but beforeunload *should* be the thing we want
// neccesarily mean a navigation.
// NOTE beforeunload is not emitted for iframes!
......@@ -98,7 +98,7 @@ function playerGone(playerId) {
// when tab is closed, tell the player is gone
// below we also have a "gone" signal listener from the content script
// which is invoked in the onbeforeunload handler of the page
// which is invoked in the pagehide handler of the page
chrome.tabs.onRemoved.addListener((tabId) => {
// Since we only get the tab id, search for all players from this tab and signal a "gone"
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment