Created
January 18, 2021 21:54
-
-
Save AWolf81/045384dd4123afce1724735da1217abd to your computer and use it in GitHub Desktop.
Web extension using snowpack & snowpack-plugin-web-ext for content-scripts
This file contains hidden or 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
// location: src/content-scripts/content-script-2.ts | |
// just to have an import | |
export function hello() { | |
return "Hello World"; | |
} |
This file contains hidden or 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
// location: src/content-scripts/index.ts | |
import { hello } from "./content-script-2"; | |
export default () => { | |
console.log(hello()); | |
console.log("Hello from content script"); // runs in popup.html page | |
} |
This file contains hidden or 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
// location: src/content-scripts/inject.ts | |
(async () => { | |
const src = chrome.extension.getURL('dist/content-scripts/index.js'); | |
const contentScript = await import(src); | |
contentScript.default(/* chrome: no need to pass it */); | |
})(); |
This file contains hidden or 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
{ | |
"manifest_version": 2, | |
"name": "snowpack-plugin-web-ext-chrome-popup-demo", | |
"version": "0.0.1", | |
"description": "Minimal demo for usage of snowpack-web-ext-plugin to create a browser extension with a content script.", | |
"permissions": [ | |
"<all_urls>" | |
], | |
"minimum_chrome_version": "61", | |
"browser_action": { | |
}, | |
"content_scripts": [ | |
{ | |
"matches": ["<all_urls>"], | |
"js": ["./dist/content-scripts/inject.js"] | |
} | |
], | |
"web_accessible_resources": [ | |
"dist/content-scripts/*" | |
] | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment