fix: skip cache-busting and wake-up reload for file:// URLs - #307
Open
jamesvillarrubia wants to merge 1 commit into
Open
fix: skip cache-busting and wake-up reload for file:// URLs#307jamesvillarrubia wants to merge 1 commit into
jamesvillarrubia wants to merge 1 commit into
Conversation
- 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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When the service worker wakes up on a
file://tab, the console fills with:and the autoreload poll fails for local files.
Root cause
Two spots assume
file://behaves likehttp(s)://:background/detect.js— wake-up reload. Theonwakeupbranch callschrome.tabs.reload(id)wheneverchrome.webRequestis present. ButwebRequestonly fires forhttp/httpsnavigations — it cannot observefile://loads (see README, issue Firefox version breaks GitHub #41). So on wake-up, afile://tab gets a pointless full reload that re-triggers the raw-text load and races the content-script re-inject, surfacing thefile:unique-security-origin error.background/xhr.js— autoreload fetch. Every URL — includingfile://paths — got?preventCache=+Date.now()appended.file:URLs aren't cached, and some Chrome versions reject the query string onfile:fetches, so the autoreload poll throws and the extension logsres.err.Fix
detect.js: guard theonwakeupreload with!win.url.startsWith('file:')sofile://tabs fall through toinject()instead of reloading.xhr.js: only append the cache-busting query string for non-file:URLs.Repro
.mdfile (file:///...) in Chrome with the extension and Allow access to file URLs enabled.chrome://extensions).Unsafe attempt to load URL ... 'file:' URLs are treated as unique security originserror in the service-worker console, and (with autoreload on) thexhrfetch error.After this patch, the wake-up path injects without reloading and the autoreload poll no longer appends a query string to
file:URLs.Related: #288, #131.