w3c / webextensions

Charter and administrivia for the WebExtensions Community Group (WECG)
Other
605 stars 56 forks source link

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

Open tophf opened 6 months ago

tophf commented 6 months ago

Benefits/goals:

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:

carlosjeurissen commented 6 months ago

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.

fregante commented 6 months ago

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 commented 2 months ago

In addition to injection. There is also the removal aspect in case content scripts get registered using registerContentScripts as mentioned in https://github.com/w3c/webextensions/issues/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).