-
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
Request immediate injection of manifest script registered with document_idle
#600
Comments
RelatedThis is somewhat related to the ability to determine when a tab is ready to receive messages: |
Safari does not currently support In general I would be supportive of something like this, we do have the support to do this internally in WebKit at least. |
Relevant previous discussions: |
Why don't you use |
@Rob--W I don’t think that resolves the issue, the script might still load long after the user called/activated the extension. I could use |
Maybe And something like @Rob--W, an example of why |
At the moment, the approach I find most compelling is @fregante's suggestion that we introduce a new I'm also interested in the idea of exposing a runtime API to let extensions request injection of a given content script, but I'm a bit uncomfortable with the suggestion that we do so based on content script declaration indices. First, this approach only works with content scripts declared in the extensions manifest; runtime declarations via I think a better approach would be to add an // manifest.json
{
"content_scripts": [{
"id": "main",
"matches": ["*://*.example.com/*"],
"scripts": ["content.js"],
"run_at": "document_idle"
}]
}
// background.js
browser.action.onClicked.addListener((tab) => {
scripting.executeScript({
target: { tab: tabId },
scriptId: "main"
// "files" and "func" omitted because the appropriate value would be reused
// by from the "main" content script's declaration.
});
}); I'm also concerned that introducing a One way to combat this is to allow |
This topic was discussed in today's meeting (meeting notes pending review before merging in #608). This specific part of the proposal was discussed in more detail:
I expressed concerns over this capability in isolation, because the currently expected behavior is for the script to execute whenever the API is called. This could be countered by introducing a way for extension authors to explicitly signal that a content script should run once per page. If that capability were to exist, then it can be combined with the existing FYI: In Firefox, there is currently no deduplication of already-injected scripts. In Chrome, content scripts are currently run only once even when specified multiple times. This is even the case if the scripts target different worlds, which someone reported before at https://issues.chromium.org/issues/324096753 ("Shared content script in different worlds conflicts with each other") |
Context
*://*/*
andrun_at: document_idle
.Problem
On larger websites, like nytimes.com, the page (and therefore the content script) takes several seconds to load. This is fine with regular usage, but if the user activates the extension, the content script cannot respond (or even receive messages) until the browser loads it.
I could use the Scripting API to manually inject it, but the browser will follow it with its own injection, or maybe cause race conditions.
Possible solutions
run_on_active_tab: true
)scripting.ensureScript(3)
, where the number is the index in the manifest)The text was updated successfully, but these errors were encountered: