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

Proposal: RunAt.before_document_start #513

Closed
bershanskiy opened this issue Jan 3, 2024 · 1 comment
Closed

Proposal: RunAt.before_document_start #513

bershanskiy opened this issue Jan 3, 2024 · 1 comment
Labels
opposed: chrome Opposed by Chrome opposed: firefox Opposed by Firefox opposed: safari Opposed by Safari

Comments

@bershanskiy
Copy link
Member

Background

Extensions can run content scripts at different stages of content document lifecycle. Currently there are 3 values, "document_start", "document_end", "document_idle" which mean that the extension content script will run no earlier than a specific stage is reached. This works well for preventing content script from running too early, but does not help if content script explicitly needs to run as early as possible.

Reference

Problem/Motivation

Some content scripts need to shim a particular API in the content page. To do this, content script must reliably run before any other script on the page.

Other solutions considered

As of time of writing, there is no simple fool-proof way to run content script early. One can do the following to add a synchronous <script> tag somewhere in the document:

  • use webRequest.StreamFilter to rewrite the document and insert a <script> tag which would execute synchronously.
  • use proxy API to redirect request to a native HTTP proxy which would rewrite the response and add the <script> tag
  • use blocking webRequest API to listen for onHeadersReceived and add HTTP response header Link to preload the script - very unreliable

Proposal

Add RunAt.before_document_start. This value means "execute content/user script as early as possible, before any other script on the page. May be, also introduce a new optional permission without a warning called scripting.before_document_start or scripting.synchroneous.

@Rob--W Rob--W added opposed: chrome Opposed by Chrome opposed: safari Opposed by Safari opposed: firefox Opposed by Firefox and removed needs-triage labels Jan 4, 2024
@Rob--W
Copy link
Member

Rob--W commented Jan 4, 2024

There is consensus on NOT supporting before_document_start because the requested behavior is exactly what document_start is supposed to do (see meeting notes, pending review in #514).

If there are bugs with specific browser implementations, file bugs on the issue trackers of the specific browsers (and optionally: link them from here for visibility).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
opposed: chrome Opposed by Chrome opposed: firefox Opposed by Firefox opposed: safari Opposed by Safari
Projects
None yet
Development

No branches or pull requests

2 participants