-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
203 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ logs | |
*.map | ||
index.js | ||
index.d.ts | ||
distribution |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "@parcel/config-webextension" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<meta name="color-scheme" content="dark light"> | ||
<script type="module" src="main.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* global chrome */ | ||
import mainHtmlUrl from 'url:../main.html'; | ||
import {isChrome} from '../../index.ts'; | ||
|
||
if (globalThis.chrome?.contextMenus?.create) { | ||
chrome.contextMenus.removeAll(); | ||
chrome.contextMenus.create({ | ||
id: 'OPEN_ALL', | ||
title: 'Open all contexts', | ||
contexts: ['action'], | ||
}); | ||
|
||
chrome.contextMenus.onClicked.addListener((info, tab) => { | ||
if (info.menuItemId === 'OPEN_ALL') { | ||
chrome.sidePanel?.open({ | ||
windowId: tab.windowId, | ||
}); | ||
chrome.runtime.openOptionsPage(); | ||
chrome.tabs.create({ | ||
url: mainHtmlUrl, | ||
}); | ||
chrome.tabs.create({ | ||
url: 'https://ephiframe.vercel.app/?iframe=' + chrome.runtime.getURL('sandbox.html'), | ||
}); | ||
|
||
chrome.tabs.create({ | ||
url: isChrome() ? 'chrome://extensions/' : 'about:debugging#/runtime/this-firefox', | ||
}); | ||
} | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import mainHtmlUrl from 'url:../main.html'; | ||
|
||
globalThis.chrome?.devtools?.panels?.create( | ||
'WEBEXT-DETECT', | ||
'icon.png', | ||
mainHtmlUrl, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
/* global chrome */ | ||
import mainHtmlUrl from 'url:../main.html'; | ||
|
||
globalThis.chrome?.offscreen?.createDocument({ | ||
url: mainHtmlUrl, | ||
reasons: [chrome.offscreen.Reason.DOM_PARSER], | ||
justification: 'Testing', | ||
}).catch(() => {}); // eslint-disable-line unicorn/prefer-top-level-await -- shh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<meta name="color-scheme" content="dark light"> | ||
<script type="module" src="main.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/* eslint-disable import/no-unassigned-import */ | ||
import * as detect from '../index.ts'; | ||
import './init/context-menu.js'; | ||
import './init/devtools-tab.js'; | ||
import './init/offscreen.js'; | ||
|
||
const table = Object.entries(detect) | ||
.filter(([key, exported]) => typeof exported === 'function' && key !== 'disableWebextDetectPageCache') | ||
.map(([key, detection]) => [key, detection()]) | ||
.sort(([keyA, resultA], [keyB, resultB]) => { | ||
if (resultA === resultB) { | ||
return keyA.localeCompare(keyB); | ||
} | ||
|
||
return resultA === true ? -1 : 1; | ||
}); | ||
|
||
console.table(table); | ||
|
||
if ('document' in globalThis) { | ||
globalThis.document.body.insertAdjacentHTML('beforeend', ` | ||
<fieldset> | ||
<legend>${detect.getContextName()}</legend> | ||
<ul> | ||
${table.map(([key, result]) => ` | ||
<li> | ||
<span> | ||
${result === true ? '✅' : (result === false ? '❌' : '')} | ||
${key} | ||
${typeof result === 'string' ? `: ${result}` : ''} | ||
</span> | ||
</li> | ||
`).join('')} | ||
</ul> | ||
</fieldset> | ||
`); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// It needs to be a standalone file or else the browser won't try to inject once per world | ||
|
||
// eslint-disable-next-line import/no-unassigned-import | ||
import './main.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
{ | ||
"$schema": "https://json.schemastore.org/chrome-manifest", | ||
"manifest_version": 3, | ||
"name": "webext-detect", | ||
"version": "0.0.0", | ||
"description": "Demonstrates the webext-detect module", | ||
"permissions": [ | ||
"contextMenus", | ||
"sidePanel", | ||
"offscreen" | ||
], | ||
"background": { | ||
"service_worker": "main.js", | ||
"type": "module", | ||
"scripts": ["main.js"] | ||
}, | ||
"action": { | ||
"default_popup": "action.html" | ||
}, | ||
"options_ui": { | ||
"page": "options.html" | ||
}, | ||
"devtools_page": "main.html", | ||
"side_panel": { | ||
"default_path": "sidepanel.html" | ||
}, | ||
"sandbox": { | ||
"pages": ["sandbox.html"] | ||
}, | ||
"web_accessible_resources": [ | ||
{ | ||
"resources": [ "sandbox.html" ], | ||
"matches": [ "https://*/*" ] | ||
} | ||
], | ||
"content_scripts": [ | ||
{ | ||
"matches": ["<all_urls>"], | ||
"js": ["main.js"] | ||
}, | ||
{ | ||
"world": "MAIN", | ||
"matches": ["<all_urls>"], | ||
"js": ["mainworld.js"] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<meta name="color-scheme" content="dark light"> | ||
<script type="module" src="main.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
# Demo for webext-detect | ||
|
||
1. Run `npm run demo:build` in the project root | ||
2. Load the extension in Chrome | ||
|
||
## Available context and how to open them | ||
|
||
Click the extension icon in the toolbar: | ||
|
||
- Popup | ||
|
||
Right-click the icon and select "Open all contexts": | ||
|
||
- Options | ||
- SidePanel | ||
- Generic extension page | ||
- Sandboxed iframe | ||
|
||
Open the devtools and select the "WEBEXT-DETECT" tab: | ||
|
||
- DevTools | ||
|
||
In `chrome://extensions`, see the open debuggable contexts: | ||
|
||
- Background | ||
- Offscreen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<meta name="color-scheme" content="dark light"> | ||
<h1>Dedicated sandbox.html page</h1> | ||
<p>This file is treated as a sandboxed page when loaded in an iframe.</p> | ||
<script type="module" src="main.js"></script> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<meta name="color-scheme" content="dark light"> | ||
<script type="module" src="main.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters