Skip to content

fregante/webext-inject-on-install

Repository files navigation

webext-inject-on-install

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 🎉

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 #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.

Related

License

MIT © Federico Brigante

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •