serversideup / webext-bridge

💬 Messaging in Web Extensions made easy. Batteries included.
https://serversideup.net/open-source/webext-bridge
MIT License
547 stars 50 forks source link

How background communicates with content #86

Closed QC2168 closed 7 months ago

QC2168 commented 7 months ago

Version

6.0.1

Current Behavior

// background
chrome.action.onClicked.addListener((tab) => {
  sendMessage('openDrawer',null,'content-script')
})
// content-script
onMessage('openDrawer',()=>{
  isOpen.value = !isOpen.value
})

But, I obtain the error

Uncaught (in promise) TypeError: When sending messages from background page, use @tabId syntax to target specific tab

Expected Behavior

I want content-script to pick up the signal normally

Steps To Reproduce

// background
chrome.action.onClicked.addListener((tab) => {
  sendMessage('openDrawer',null,'content-script')
})
// content-script
onMessage('openDrawer',()=>{
  isOpen.value = !isOpen.value
})

Anything else?

No response

QC2168 commented 7 months ago

I want to notify content-script when I click the plug-in icon