Closed JTInfinite closed 2 years ago
Sending a message from popup to background doesn't seem to work for me.
I am using this package in a Vue project.
//popup.ts import { createApp } from 'vue' import App from './Popup.vue' import '../styles' import { sendMessage } from 'webext-bridge/popup' (async () => { const resBG = await sendMessage('test-message', { text: "Popup" }, 'background') console.log(`[popup] Got ${ resBG }`); const resCS = await sendMessage('test-message', { text: "Popup" }, 'content-script') console.log(`[popup] Got ${ resCS }`); })() const app = createApp(App) app.mount('#app')
Background receives this message but throws an error:
Uncaught (in promise) TypeError: When sending messages from background page, use @tabId syntax to target specific tab
Background looks like this:
import { onMessage } from 'webext-bridge/background' onMessage('test-message', async (message) => { const { data, sender } = message console.log(`[background] Got test message from ${ sender.context }@${ sender.tabId }. Data: ${ JSON.stringify(data) } `); return `Hello` })
that console message shows:
[background] Got test message from popup@NaN. Data: [object Object]
Content script does not receive anything from the popup.
Is it possible to communicate with the popup in this way or have I got it wrong?
Thanks
Closing this as I realise it is basically the same as #37
Sending a message from popup to background doesn't seem to work for me.
I am using this package in a Vue project.
Background receives this message but throws an error:
Uncaught (in promise) TypeError: When sending messages from background page, use @tabId syntax to target specific tab
Background looks like this:
that console message shows:
[background] Got test message from popup@NaN. Data: [object Object]
Content script does not receive anything from the popup.
Is it possible to communicate with the popup in this way or have I got it wrong?
Thanks