🧩 Plasmo Developers�PD
🧩 Plasmo Developers3y ago
12 replies
Asif

How send message from background to content script UI

My background.js
chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
  // read changeInfo data and do something with it (like read the url)
  if (changeInfo.url) {
    // console.log(changeInfo)
    // do something here
    chrome.tabs.sendMessage(tabId, { greet: "hello" })
  }
})



And in the content/panel.js

useEffect(() => {
  chrome.runtime.onMessage.addListener(function (msg, sender, sendResponse) {
      console.log("Received %o from %o, frame", msg, sender.tab, sender.frameId)
  })
}, [])



I think there is no issue with permission. I have given the permission below:

"permissions": [
"tabs",
"activeTab"
]


After doing this the extension throws me an error.
Uncaught (in promise) Error: Could not establish connection. Receiving end does not exist.
Context
static/background/index.js



Whats the problem with my code? Please explain if you know
232.png
Was this page helpful?