From 0954f1c510caad61cbc47813e7e0e08b70e55e63 Mon Sep 17 00:00:00 2001 From: Ignatius Bagus Date: Thu, 7 Dec 2023 14:22:14 +0700 Subject: [PATCH] fix: execute sensor script on unloaded --- static/background.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/static/background.js b/static/background.js index 2f21d62..2681d2e 100644 --- a/static/background.js +++ b/static/background.js @@ -70,7 +70,7 @@ function courier(tabId, changed) { // because `detail` in the dispatched custom events is `null` const script = document.createElement('script'); script.setAttribute('src', source); - document.documentElement.appendChild(script); + document.head.appendChild(script); // // TODO: reenable profiler // if (message.type === 'bridge::ext/profiler' && message.payload) { @@ -108,7 +108,7 @@ function courier(tabId, changed) { chrome.tabs.onActivated.addListener(({ tabId }) => sensor(tabId)); chrome.tabs.onUpdated.addListener( - (tabId, changed) => changed.status === 'loading' && sensor(tabId), + (tabId, changed) => changed.status === 'unloaded' && sensor(tabId), ); /** @param {number} tabId */ @@ -122,7 +122,7 @@ async function sensor(tabId) { document.querySelector(`script[src="${source}"]`)?.remove(); const script = document.createElement('script'); script.setAttribute('src', source); - document.documentElement.appendChild(script); + document.head.appendChild(script); document.addEventListener('SvelteDevTools', ({ detail }) => { chrome.runtime.sendMessage(detail);