webext-inject-on-install

June 30, 2025 · View on GitHub

Automatically add content scripts to existing tabs when your extension is installed.

Safari and Firefox actually already do this natively, so this module is automatically disabled there.

  • Browsers: Chrome 130+
  • Manifest: v3 (v2 was last supported in webext-inject-on-install v2.3.0)
  • Permissions: scripting, storage, (tabs or host_permissions that includes all the hosts specified in content_scripts)
  • Context: background

Sponsored by PixieBrix :tada:

Install

npm install webext-inject-on-install

Or download the standalone bundle to include in your manifest.json.

Usage

It registers automatically:

import "webext-inject-on-install";

How it works

  1. It gets the list of content scripts from the manifest
  2. For each content script group, it looks for open tabs that are not discarded (discarded tabs are already handled by the browser)
  3. It injects the scripts into the focused tabs matching the matches patterns (exclude_matches is not supported https://github.com/fregante/webext-inject-on-install/issues/5)
  4. The remaining tabs are tracked and they receive the applicable scripts when they're activated.
  5. Once the list of tracked tabs is empty, the listeners are removed.

License

MIT © Federico Brigante