-
Notifications
You must be signed in to change notification settings - Fork 74
Closed
Labels
supportive: firefoxSupportive from FirefoxSupportive from Firefoxsupportive: safariSupportive from SafariSupportive from Safari
Description
Basic Use Case: Users often want an exclusion/allow list functionality to disable add-ons on certain URLs.
Goal:
- run or not run code in tabs depending on user defined urls/patterns
- browser action icon should reflect whether the code runs or does not run
- ideally avoid the
tabspermission as self-deactivation is not a main feature of an add-on. It is kinda contradictory that content script disabling requires loosening the permissions.
Attempts:
Block the content script injection:
Approach:
scripting.registerContentScripts() seems like a wonderful fit for this, because it provides the excludeMatches functionality wherefore no knowledge about the tab urls has to be exposed.
- Store the exclusions in
browser.storage. - Retrieve the exclusions in the background script.
- Inside the background script call
scripting.registerContentScripts()(orscripting.updateContentScripts()) with the exclusions asexcludeMatchesto register the content script.
Problems:
scripting.registerContentScripts()does not inject the script into already existing tabs. Any workaround viascripting.executeScript()requires thetabspermission because it should only be called for tabs whose url is not listed in the exclusions.- Adding an url/pattern to
excludeMatches(viascripting.updateContentScripts()) does not remove/disable already injected content scripts.
Drawbacks:
- Detecting whether the content script is injected or not from the background page is only possible via messaging from/to the content script. So toggling the browser action icon state would be possible if the above problems were solved.
Block the code inside the content script:
Approach:
- Register the content script via the
content_scriptsmanifest key - Store the exclusions in the
browser.storage. - Retrieve the exclusions in the content script.
- Inside the content script check whether whether the tabs URL matches any exclusion and run or not run the main content script's code.
Problems:
- No direct access to the tab url in iframes (requires passing the
window.location.hrefto background page and then back to all frames) or using the privacy unfriendlypostMessageAPI. The browser action icon either requires passing the url from the content script to the background script since it does not have access to the tab url without thetabspermission, or some other messaging.
Drawbacks:
- Unnecessary injection/workload
Conclusion:
So far only the latter approach really works, but for a seemingly simple functionality as whitelisting/blacklisting it is cumbersome to implement. Also it feels wrong to rely on content script code while the goal is to avoid any content script injection.
Possible solutions:
- Allow
scripting.registerContentScripts()to inject into existing tabs and also unloading it when it becomes excluded viaexcludeMatches.
Related requests: Provide the tab url regardless of theEdit: This is already the case.tabspermission if the add-on has host permissions for the respective tab. This would still require the content script to be injected at all times but at least require less implementation overhead for the background script code.
Metadata
Metadata
Assignees
Labels
supportive: firefoxSupportive from FirefoxSupportive from Firefoxsupportive: safariSupportive from SafariSupportive from Safari