mubaidr / vite-vue3-browser-extension-v3

Another vite powered web extension (chrome, firefox, etc.) starter template.
506 stars 67 forks source link

I cant get working OnMessage and sendMessage from webext-bridge. No one direction working. #29

Closed mttzzz closed 1 year ago

mttzzz commented 1 year ago

popup => background background => popup content-script => popup, background

Maybe need some magic?

i use examples from documentation webext-bridge.

mubaidr commented 1 year ago

In your content-script

import { sendMessage } from "webext-bridge/content-script";

const res = await sendMessage(
  "get-data",
  {},
  "background"
);

console.log(res) // anything

and in your background:

import { onMessage } from "webext-bridge/background";

onMessage("get-data", ({ data }) => {
  return 'anything';
});

More usage details here: https://github.com/zikaari/webext-bridge#example