Skip to content

Drop activeTab support #78

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 1, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ jobs:
- run: npm run vitest

Test:
runs-on: ubuntu-latest
# https://github.com/puppeteer/puppeteer/issues/12818#issuecomment-2415915338
runs-on: ubuntu-22.04
strategy:
fail-fast: false
matrix:
Expand Down
9 changes: 5 additions & 4 deletions .github/workflows/esm-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ jobs:
needs: Pack
steps:
- uses: actions/download-artifact@v4
- run: npm install --omit=dev ./artifact rollup@2 @rollup/plugin-node-resolve
- run: npm install --omit=dev ./artifact rollup@4 @rollup/plugin-node-resolve
- run: echo "$IMPORT_STATEMENT" > index.js
- run: npx rollup -p node-resolve index.js
Vite:
Expand All @@ -84,10 +84,11 @@ jobs:
needs: Pack
steps:
- uses: actions/download-artifact@v4
- run: echo '{"type":"module"}' > package.json
- run: npm install --omit=dev ./artifact @sindresorhus/tsconfig
- run: echo "$IMPORT_STATEMENT" > index.ts
- run: echo "$IMPORT_STATEMENT" > index.mts
- run: >
echo '{"extends":"@sindresorhus/tsconfig","files":["index.ts"]}' >
echo '{"extends":"@sindresorhus/tsconfig","files":["index.mts"]}' >
tsconfig.json
- run: npx --package typescript -- tsc
- run: cat distribution/index.js
- run: cat distribution/index.mjs
1 change: 0 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
!/distribution/*
*.test.*
!/utils.*
!/including-active-tab.*
10 changes: 1 addition & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "webext-dynamic-content-scripts",
"version": "10.0.4",
"description": "WebExtension module: Automatically registers your `content_scripts` on domains added via `permission.request` or on `activeTab`",
"description": "WebExtension module: Automatically registers your `content_scripts` on domains added via `permission.request`",
"keywords": [
"contentscript",
"register",
Expand All @@ -14,7 +14,6 @@
"chrome",
"firefox",
"browser",
"activetab",
"extension"
],
"repository": "fregante/webext-dynamic-content-scripts",
Expand All @@ -27,10 +26,6 @@
"types": "./distribution/index.d.ts",
"default": "./distribution/index.js"
},
"./including-active-tab.js": {
"types": "./distribution/including-active-tab.d.ts",
"default": "./distribution/including-active-tab.js"
},
"./utils.js": {
"types": "./distribution/utils.d.ts",
"default": "./distribution/utils.js"
Expand Down Expand Up @@ -137,9 +132,6 @@
"https://dynamic-ephiframe.vercel.app/Dynamic?iframe=./Inner",
"https://dynamic-ephiframe.vercel.app/Dynamic?iframe=https://static-ephiframe.vercel.app/Static-inner",
"https://static-ephiframe.vercel.app/Static?iframe=https://dynamic-ephiframe.vercel.app/Dynamic-inner",
"https://extra-ephiframe.vercel.app/Inject-via-context-menu-please",
"https://extra-ephiframe.vercel.app/Inject-via-context-menu-please?iframe=https://static-ephiframe.vercel.app/Static-inner",
"https://extra-ephiframe.vercel.app/Inject-via-context-menu-please?iframe=https://dynamic-ephiframe.vercel.app/Dynamic-inner",
"chrome://extensions/"
]
}
Expand Down
13 changes: 0 additions & 13 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,6 @@ navigator.importScripts('webext-dynamic-content-scripts.js');
}
```

### `activeTab` tracking

By default, the module will only inject the content scripts into newly-permitted hosts, but it will ignore temporary permissions like `activeTab`. If you also want to automatically inject the content scripts into every frame of tabs as soon as they receive the `activeTab` permission, import a different entry point **instead of the default one.**

```js
import 'webext-dynamic-content-scripts/including-active-tab.js';
```

> **Note**
> This does not work well in Firefox because of some compounding bugs:
> - `activeTab` seems to be lost after a reload
> - further `contextMenu` clicks receive a moz-extension URL rather than the current page’s URL

### Additional APIs

#### `isContentScriptRegistered(url)`
Expand Down
88 changes: 0 additions & 88 deletions source/active-tab.ts

This file was deleted.

74 changes: 0 additions & 74 deletions source/including-active-tab.ts

This file was deleted.

44 changes: 0 additions & 44 deletions source/simple-event-target.ts

This file was deleted.

14 changes: 1 addition & 13 deletions test/demo-extension/mv2/background.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
import 'webext-dynamic-content-scripts/including-active-tab.ts';

chrome.contextMenus.create({
title: 'Enable activeTab permission',
}, () => {
if (chrome.runtime.lastError) {
// Shush
}
});

chrome.contextMenus.onClicked.addListener(() => {
console.log('Context menu clicked');
});
import 'webext-dynamic-content-scripts';

console.log('Background loaded');
2 changes: 0 additions & 2 deletions test/demo-extension/mv2/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
"version": "0.0.0",
"manifest_version": 2,
"permissions": [
"activeTab",
"webNavigation",
"contextMenus",
"https://dynamic-ephiframe.vercel.app/*",
"https://accepted-ephiframe.vercel.app/*"
],
Expand Down
14 changes: 1 addition & 13 deletions test/demo-extension/mv3/background.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,3 @@
import 'webext-dynamic-content-scripts/including-active-tab.ts';

chrome.contextMenus.create({
title: 'Enable activeTab permission',
}, () => {
if (chrome.runtime.lastError) {
// Shush
}
});

chrome.contextMenus.onClicked.addListener(() => {
console.log('Context menu clicked');
});
import 'webext-dynamic-content-scripts';

console.log('Background loaded');
2 changes: 1 addition & 1 deletion test/demo-extension/mv3/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "webext-dynamic-content-scripts-mv3",
"version": "0.0.0",
"manifest_version": 3,
"permissions": ["webNavigation", "scripting", "contextMenus", "activeTab", "storage"],
"permissions": ["webNavigation", "scripting", "storage"],
"host_permissions": [
"https://dynamic-ephiframe.vercel.app/*",
"https://accepted-ephiframe.vercel.app/*"
Expand Down