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, (tabsorhost_permissionsthat includes all the hosts specified incontent_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
- It gets the list of content scripts from the manifest
- For each content script group, it looks for open tabs that are not discarded (discarded tabs are already handled by the browser)
- It injects the scripts into the focused tabs matching the
matchespatterns (exclude_matchesis not supported https://github.com/fregante/webext-inject-on-install/issues/5) - The remaining tabs are tracked and they receive the applicable scripts when they're activated.
- Once the list of tracked tabs is empty, the listeners are removed.
Related
- webext-dynamic-content-scripts - Automatically registers your
content_scriptson domains added viapermission.request - webext-content-scripts - Utility functions to inject content scripts in WebExtensions.
- webext-options-sync - Helps you manage and autosave your extension's options.
- More…
License
MIT © Federico Brigante