-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
API limitation: content scripts URL matches and History API, Navigation API, BFCache #523
Comments
This would help avoid injecting unnecessarily in the entire site with a listener for navigation.onnavigate (Chrome only as of now) or using the background script with chrome.tabs.onUpdated (wakes up the background script for unrelated URLs) or chrome.webNavigation.onHistoryStateUpdated (adds a scary installation warning). Since it would be a breaking change, a new key in the declaration is necessary e.g. |
This seems worth discussion, but I expect this may be behaviour we want to keep and just ensure we have adequately documented. When the URL changes to one that matches a content script, this isn't too tricky - we can just inject the script. This gets a lot harder if we try to be consistent with when you navigate away though - there's no way to "uninject" a content script that is already running and may have made changes to the page. |
That applies to the reverse situation though: first load matches, successive AJAX loads and URL changes no longer match. |
For sure. I think the thing we need to decide is whether having some soft navigation controls increases the confusion because now it seems like we have handling for that. |
This is pretty much the same request as #446. |
Meeting on 15 Feb 2024: agreed to keep implementation as is and add notes to MDN. |
Summary
Content Script declarations can contain match patterns with non-empty paths (e.g.,
https://example.com/subpage
with path/subpage
). The match is evaluated only on the initial document navigation and not on URL replacement in response to History API invocation. (BFCache discards a document if there was an extension-related event affecting it between document entering BFCache and getting restored.)To sum up, currently CS match patterns with non-
/*
or/*/*
paths may not be reliable when pages use History or Navigation API.Example
Example extension
manifest.json
content-script.js
Steps
https://example.com/
ran
history.replaceState(undefined,undefined,"/sub")
https://example.com/sub
but theran
did not appearran
error message logged in the consoleThe text was updated successfully, but these errors were encountered: