Skip to content

Commit 2eae875

Browse files
committed
docs: update README for improved clarity on plugin behavior and permissions
- Clarified content script activation flow and error handling. - Expanded details on required permissions and their usage. - Added additional troubleshooting steps for common issues.
1 parent 764f84a commit 2eae875

2 files changed

Lines changed: 43 additions & 13 deletions

File tree

README.md

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,42 @@
55
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE.md)
66
[![CI](https://github.com/addon-stack/plugin-reg-cs/actions/workflows/ci.yml/badge.svg)](https://github.com/addon-stack/plugin-reg-cs/actions/workflows/ci.yml)
77

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

1010
## Key Features
1111

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
1516
- **Zero Configuration**: Works out of the box with your existing manifest content script definitions
1617

1718
## How It Works
1819

19-
When your extension is installed, this plugin:
20+
On the extension’s initial install (not on updates), the plugin:
2021

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

2635
## Required Permissions
2736

28-
This plugin requires the following permissions in your manifest:
37+
This plugin relies on the following permissions:
2938

3039
- **`tabs`**: Needed to query and access tab information for content script injection
3140
- **`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`
3242

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

3545
## Installation
3646

@@ -68,9 +78,11 @@ export default defineConfig({
6878
});
6979
```
7080

71-
7281
## Troubleshooting
7382

7483
If your content scripts aren't being injected:
7584

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

package-lock.json

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)