From a327405a9dc9f728e827d9bcc0dc99e6c2a73f5e Mon Sep 17 00:00:00 2001 From: James Villarrubia Date: Fri, 4 Sep 2026 16:06:35 -0400 Subject: [PATCH] fix: skip cache-busting and wake-up reload for file:// URLs - detect.js: the onwakeup branch calls chrome.tabs.reload() when chrome.webRequest is present, but webRequest cannot observe file:// navigations (it only fires for http/https). Reloading a file:// tab on service-worker wake-up re-triggers the raw-text load and races the content script, producing the 'Unsafe attempt to load URL ... file: URLs are treated as unique security origins' console error when the page is reloaded while the extension re-injects. Skip the reload for file: URLs and fall through to inject() instead. - xhr.js: fetch() was appending '?preventCache=' + Date.now() to every URL including file:// paths. file: URLs are not cached and some Chrome versions reject the query string on file: fetches, surfacing as a failed autoreload poll. Only append the cache-buster for non-file: URLs. --- background/detect.js | 2 +- background/xhr.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/background/detect.js b/background/detect.js index ab3bff9..09b3ead 100644 --- a/background/detect.js +++ b/background/detect.js @@ -65,7 +65,7 @@ md.detect = ({storage: {state}, inject}) => { } if (detect(win.header, win.url)) { - if (onwakeup && chrome.webRequest) { + if (onwakeup && chrome.webRequest && !win.url.startsWith('file:')) { onwakeup = false chrome.tabs.reload(id) } diff --git a/background/xhr.js b/background/xhr.js index c06388c..a908b24 100644 --- a/background/xhr.js +++ b/background/xhr.js @@ -5,7 +5,8 @@ md.xhr = () => { ;(async () => { await new Promise(async (resolve, reject) => { try { - var res = await fetch(url + '?preventCache=' + Date.now()) + var bust = url.startsWith('file:') ? '' : '?preventCache=' + Date.now() + var res = await fetch(url + bust) done(null, await res.text()) } catch (err) {