Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Popup has no tabId so can't message between it and background #45

Closed
JTInfinite opened this issue Nov 2, 2022 · 1 comment
Closed

Comments

@JTInfinite
Copy link

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

@JTInfinite
Copy link
Author

Closing this as I realise it is basically the same as #37

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant