Skip to content

Instantly share code, notes, and snippets.

@AWolf81
Created January 18, 2021 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AWolf81/045384dd4123afce1724735da1217abd to your computer and use it in GitHub Desktop.
Save AWolf81/045384dd4123afce1724735da1217abd to your computer and use it in GitHub Desktop.
Web extension using snowpack & snowpack-plugin-web-ext for content-scripts
// location: src/content-scripts/content-script-2.ts
// just to have an import
export function hello() {
return "Hello World";
}
// 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
}
// 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 */);
})();
{
"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