Skip to content

Commit

Permalink
example webext-bridge
Browse files Browse the repository at this point in the history
  • Loading branch information
reedHam committed Apr 24, 2022
1 parent 56cafe7 commit 03f0a7f
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 2 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"scripts": {
"start": "vite",
"dev": "vite",
"build": "vite build && web-ext build --overwrite-dest -s ./build/dist -a ./build/ && cp ./build/*.zip /mnt/e/extensions/",
"build": "vite build && web-ext build --overwrite-dest -s ./build/dist -a ./build/ && cp -f ./build/*.zip /mnt/e/extensions/",
"sign": "web-ext sign --api-key $(grep WEB_EXT_API_KEY .env | cut -d '=' -f2) --api-secret $(grep WEB_EXT_API_SECRET .env | cut -d '=' -f2) -s ./build/dist -a ./build/",
"serve": "vite preview"
},
Expand Down
9 changes: 8 additions & 1 deletion src/background/background.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
/**
* The background script for the extension is responsible for sending requests to the servers using fetch.
*/
*/
// Inside background script
import { onMessage } from 'webext-bridge'

onMessage('test', ({ data: { a, b } }) => {
console.log(a, b);
return { result: true };
});
4 changes: 4 additions & 0 deletions src/scripts/youtube.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
/**
* Responsible for parsing youtube for specific data, e.g. urls, tags, comments, etc.
*/

import { sendMessage } from 'webext-bridge';

sendMessage("test", { a: "speed", b: 2 }).then(console.log);
7 changes: 7 additions & 0 deletions src/shim.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { ProtocolWithReturn } from 'webext-bridge'

declare module 'webext-bridge' {
export interface ProtocolMap {
test: ProtocolWithReturn<{ a: string, b: number }, { result: boolean }>
}
}
1 change: 1 addition & 0 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export default defineConfig({
}),
],
build: {
minify: 'terser',
outDir: path.resolve(__dirname, "build/dist"),
target: 'esnext',
polyfillDynamicImport: false,
Expand Down

0 comments on commit 03f0a7f

Please sign in to comment.