|
5 | 5 | [](LICENSE.md) |
6 | 6 | [](https://github.com/addon-stack/plugin-reg-cs/actions/workflows/ci.yml) |
7 | 7 |
|
8 | | -A plugin for [Addon Bone](https://addonbone.com) that automatically registers and injects content scripts when your browser extension is installed. |
| 8 | +A plugin for [Addon Bone](https://addonbone.com) that automatically registers and injects content scripts on first install, as soon as the required permissions are granted. |
9 | 9 |
|
10 | 10 | ## Key Features |
11 | 11 |
|
12 | | -- **Immediate Content Script Activation**: Automatically injects your content scripts into existing tabs that match your URL patterns when the extension is first installed |
13 | | -- **Full Support for Content Script Options**: Works with all manifest content script properties including `run_at`, `all_frames`, `match_about_blank`, and execution world |
14 | | -- **Error Handling**: Gracefully handles injection failures with detailed error logging |
| 12 | +- **Immediate Content Script Activation**: Injects your content scripts into already open tabs that match your URL patterns right after installation (no manual refresh needed) |
| 13 | +- **Respects Permissions Flow**: Waits for required API and host permissions; injects immediately when they are available (either granted at install or later) |
| 14 | +- **Full Support for Content Script Options**: Works with manifest content script properties including `run_at`, `all_frames`, `match_about_blank`, and execution world |
| 15 | +- **Error Handling**: Uses best‑effort injection with detailed error logging without blocking other tabs/files |
15 | 16 | - **Zero Configuration**: Works out of the box with your existing manifest content script definitions |
16 | 17 |
|
17 | 18 | ## How It Works |
18 | 19 |
|
19 | | -When your extension is installed, this plugin: |
| 20 | +On the extension’s initial install (not on updates), the plugin: |
20 | 21 |
|
21 | | -1. Reads the `content_scripts` section from your extension's manifest |
22 | | -2. Finds all open tabs that match the URL patterns defined in your content scripts |
23 | | -3. Injects the specified JavaScript and CSS files into those tabs |
24 | | -4. This ensures users can immediately see and use your extension without needing to refresh their tabs |
| 22 | +1. Reads your manifest’s `content_scripts` and collects URL patterns from each script’s `matches`. |
| 23 | +2. Treats those URL patterns as required host permissions, alongside the API permissions `tabs` and `scripting`. |
| 24 | +3. Checks whether these permissions are already granted: |
| 25 | + - If yes, it immediately injects the specified JS and CSS files into all currently open tabs that match. |
| 26 | + - If not, it subscribes to permission changes and automatically injects once the browser/user grants them (no reload required). The listener is removed after injection. |
| 27 | +4. Injection behavior: |
| 28 | + - Skips tabs that are frozen or discarded and only injects into tabs with a valid ID. |
| 29 | + - JavaScript is injected with support for `run_at`, `match_about_blank`, `all_frames`, and execution `world`. |
| 30 | + - CSS is injected with support for `run_at` and `match_about_blank`. |
| 31 | + - Errors for individual files/tabs are logged but do not stop other injections (best‑effort via Promise.allSettled). |
| 32 | + |
| 33 | +Note: This automatic registration runs only on the first install event. It doesn’t re‑run on extension updates. |
25 | 34 |
|
26 | 35 | ## Required Permissions |
27 | 36 |
|
28 | | -This plugin requires the following permissions in your manifest: |
| 37 | +This plugin relies on the following permissions: |
29 | 38 |
|
30 | 39 | - **`tabs`**: Needed to query and access tab information for content script injection |
31 | 40 | - **`scripting`**: Required to inject scripts and CSS into web pages |
| 41 | +- **Host permissions for your `matches`**: The same URL patterns you use in `content_scripts.matches` |
32 | 42 |
|
33 | | -These permissions are automatically requested by the plugin and are essential for its functionality. |
| 43 | +The plugin declares and checks these permissions and injects as soon as the browser grants them. It does not actively call `chrome.permissions.request`; ensure your manifest and/or your own UI flow prompts the user to grant the needed host permissions. |
34 | 44 |
|
35 | 45 | ## Installation |
36 | 46 |
|
@@ -68,9 +78,11 @@ export default defineConfig({ |
68 | 78 | }); |
69 | 79 | ``` |
70 | 80 |
|
71 | | - |
72 | 81 | ## Troubleshooting |
73 | 82 |
|
74 | 83 | If your content scripts aren't being injected: |
75 | 84 |
|
76 | | -- Make sure you have included the necessary URL patterns in `host_permissions` in your manifest, otherwise the API won't have access to those tabs |
| 85 | +- Ensure the necessary URL patterns are present in `host_permissions` (or are otherwise granted by the user); without host permissions the API can’t access those tabs |
| 86 | +- Remember: injection is triggered only on the initial install. To re‑test, remove the extension and install it again |
| 87 | +- Some pages (e.g., Chrome Web Store, browser internal pages) are restricted and cannot be scripted |
| 88 | +- If a tab is discarded/frozen, wake it (focus or reload) and try again |
0 commit comments