Skip to content
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

Provide method for content scripts to only run on certain domains in Chrome #284

Open
Tracked by #48
rhelmer opened this issue Jun 30, 2022 · 2 comments
Open
Tracked by #48
Assignees

Comments

@rhelmer
Copy link
Contributor

rhelmer commented Jun 30, 2022

Firefox supports dynamically loading content scripts, but until Chrome ships an equivalent API we don't have a way to restrict content scripts to only run on certain domains (specified as match patterns).

In PR #281 we attempted to write a roll-up plugin to generate entries , but Chrome cannot handle the ~4k sample of domains from the Beyond the Paywall study that I tested.

A few approaches come to mind:

  1. content scripts could message-pass with the background script/serviceworker to determine if they should run
  2. a list of allowed domains could be inlined into the content scripts

Since WebScience is built by the caller, I think both of these are pretty easy to do. The trade-offs are that (1) involves more messaging and runtime overhead, and (2) will cause content scripts to be larger on average, but no messaging would be required and the content scripts could run totally standalone.

(1) is probably the most flexible, and it might end up mattering if there are several content scripts that filter on a very large set of match patterns.

@rhelmer
Copy link
Contributor Author

rhelmer commented Jul 15, 2022

It looks like this might be supported in Chrome now, Manifest v3 only:

https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/scripting/registerContentScripts#browser_compatibility

Firefox supports it in MV3 as of 101, and MV2 as of 102+, so I think we might be able to switch to this now.

@rhelmer rhelmer self-assigned this Jul 15, 2022
@rhelmer
Copy link
Contributor Author

rhelmer commented Jul 15, 2022

OK this seems to work testing latest Chrome + MV3, we will need to make a few adjustments:

  • permissions.js needs to use host_permissions manifest key for MV3, and continue using permissions for Firefox+MV2
  • extensions now require scripting permission
  • we should remove the contentScript.js module and simply use browser.scripting API which is cross-browser now

rhelmer added a commit that referenced this issue Jul 16, 2022
rhelmer added a commit that referenced this issue Jul 25, 2022
rhelmer added a commit that referenced this issue Aug 4, 2022
fixes issue #284, use new cross-browser scripting api for registering…
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant