diff --git a/extension/content-script.js b/extension/content-script.js --- a/extension/content-script.js +++ b/extension/content-script.js @@ -607,10 +607,11 @@ 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! sendPlayerGone(); }); diff --git a/extension/extension-mpris.js b/extension/extension-mpris.js --- a/extension/extension-mpris.js +++ b/extension/extension-mpris.js @@ -98,7 +98,7 @@ // 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" playerTabGone(tabId);