Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/fregante/webext-inject-on-install
Automatically add content scripts to existing tabs when your extension is installed. Chrome
https://github.com/fregante/webext-inject-on-install
Last synced: 3 days ago
JSON representation
Automatically add content scripts to existing tabs when your extension is installed. Chrome
- Host: GitHub
- URL: https://github.com/fregante/webext-inject-on-install
- Owner: fregante
- License: mit
- Created: 2016-08-23T04:25:21.000Z (about 8 years ago)
- Default Branch: main
- Last Pushed: 2024-07-01T08:45:52.000Z (4 months ago)
- Last Synced: 2024-10-17T08:33:56.315Z (18 days ago)
- Language: TypeScript
- Homepage: https://npm.im/webext-inject-on-install
- Size: 554 KB
- Stars: 18
- Watchers: 3
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: readme.md
- License: license
Awesome Lists containing this project
README
# webext-inject-on-install [![][badge-gzip]][link-bundlephobia]
[badge-gzip]: https://img.shields.io/bundlephobia/minzip/webext-inject-on-install.svg?label=gzipped
[link-bundlephobia]: https://bundlephobia.com/result?p=webext-inject-on-install> Automatically add content scripts to existing tabs when your extension is installed.
Firefox actually already does this natively, so this module is automatically disabled there.
- Browsers: Chrome, Firefox, and Safari
- Manifest: v2 and v3
- Permissions: `tabs` + explicit host permissions in `permissions`; in Manifest v3 you'll also need `scripting`
- Context: `background`**Sponsored by [PixieBrix](https://www.pixiebrix.com)** :tada:
## Install
```sh
npm install webext-inject-on-install
```Or download the [standalone bundle](https://bundle.fregante.com/?pkg=webext-inject-on-install) to include in your `manifest.json`.
## Usage
It registers automatically:
```js
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 script into the tabs matching the `matches` patterns (`exclude_matches` is not supported https://github.com/fregante/webext-dynamic-content-scripts/issues/5)
4. If the tab count exceeds 10 (each), it injects into the tabs only when they become active. (persistent background pages only https://github.com/fregante/webext-dynamic-content-scripts/issues/4)## Related
- [webext-dynamic-content-scripts](https://github.com/fregante/webext-dynamic-content-scripts) - Automatically registers your `content_scripts` on domains added via `permission.request`
- [webext-content-scripts](https://github.com/fregante/webext-content-scripts) - Utility functions to inject content scripts in WebExtensions.
- [webext-options-sync](https://github.com/fregante/webext-options-sync) - Helps you manage and autosave your extension's options.
- [More…](https://github.com/fregante/webext-fun)## License
MIT © [Federico Brigante](https://fregante.com)