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

manifest key to enable automatic injection of content scripts after installation/update #617

Open
tophf opened this issue May 21, 2024 · 3 comments
Labels
needs-triage: chrome Chrome needs to assess this issue for the first time supportive: firefox Supportive from Firefox supportive: safari Supportive from Safari

Comments

@tophf
Copy link

tophf commented May 21, 2024

Benefits/goals:

  • Fixes inconsistency (Chrome doesn't do it, Firefox and Safari do).
  • Makes the extension immediately usable.
  • Simplifies code: no need for a nontrivial workaround that requires duplicating matches in host_permissions and doesn't support exclude_matches yet (#123).
  • Doesn't require reloading the tabs, which may lose their state (games, modern infinite-scroll pages).
  • Solves a common pain point for new developers so they don't waste a lot of time in debugger/stackoverflow/etc.

Possible solutions:

  1. "run_at": ["document_start", "extension_installed", "extension_enabled"] i.e. an alternative array syntax for run_at
  2. "run_at_extension": ["installed", "enabled"] i.e. an additional key
  3. "run_at_installed": true and "run_at_enabled": true
  4. "run_at_installed_or_enabled": true

Notes:

  • In 1 and 2 the browser should disallow invalid/duplicate values.
  • The solution should also apply to #600 e.g. "extension_invoked" in 1, "invoked" in 2, "run_at_invoked" in 3 and 4.
  • Eventually this should be the default mode, but for now the current default behavior should be explicitly documented:
@github-actions github-actions bot added needs-triage: chrome Chrome needs to assess this issue for the first time needs-triage: firefox Firefox needs to assess this issue for the first time needs-triage: safari Safari needs to assess this issue for the first time labels May 21, 2024
@carlosjeurissen
Copy link
Contributor

carlosjeurissen commented May 21, 2024

Very much in favour of having this be aligned cross browsers! Safari also injects content scripts right after installation.

As for the possible solutions. More in favour of 2-4. As 1; using an array for "run_at" would not be backwards compatible. Mixing the two also seems confusing rather than clarifying.

@xeenon xeenon added supportive: safari Supportive from Safari and removed needs-triage: safari Safari needs to assess this issue for the first time labels May 22, 2024
@fregante
Copy link

This is also something I wrote some code for (https://github.com/fregante/webext-inject-on-install) but it requires the tabs and scripting permissions.

Related requests:

Here's what they could look like:

  {
    "content_scripts": [{
      "id": "main",
      "matches": ["*://*.example.com/*"],
      "scripts": ["content.js"],
      "run_at": "document_idle",
+     "run_on_active_tab": true,
+     "run_on_extension_enabled": true
    }]
  }

or

  {
    "content_scripts": [{
      "id": "main",
      "matches": ["*://*.example.com/*"],
      "scripts": ["content.js"],
      "run_at": "document_idle",
+     "run_on": ["active_tab", "extension_enabled"]
    }]
  }

or combine it with run_at

  {
    "content_scripts": [{
      "id": "main",
      "matches": ["*://*.example.com/*"],
      "scripts": ["content.js"],
+     "run_at": ["document_idle", "active_tab", "extension_enabled"]
    }]
  }

@carlosjeurissen
Copy link
Contributor

In addition to injection. There is also the removal aspect in case content scripts get registered using registerContentScripts as mentioned in #653.

So we might want to come up with a different naming which also includes the above mentioned behaviour of removing already injected styles (not applying to scripts as injected scripts can not be reversed).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-triage: chrome Chrome needs to assess this issue for the first time supportive: firefox Supportive from Firefox supportive: safari Supportive from Safari
Projects
None yet
Development

No branches or pull requests

5 participants