w3c / webextensions

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

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

Open tophf opened 1 month ago

tophf commented 1 month 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 1 month 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 1 month 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"]
    }]
  }