On chrome extension v3 how to know if there is at least one runtime listener on

I’m trying to build a very simple chrome extension v3, but most of the content I see out there [includig stackoverflow] no longer works because it was directd to v2.

there is two problems that i need to address:

on my backgroud script if i call chrome.runtime.sendMessage and the popup is not active, the javascript throws an error

Uncaught (in promise) Error: Could not establish connection. Receiving end does not exist.

so it comes question 1

is there a way to check if there are any current listeners for chrome.runtime.sendMessage on manifest v3???

question 2

how can i, from the background script, start the popup? or display any visual message to the user;??

  • 1) No, but you can add .catch(err => ...) and check err.message. 2) In the future there will be chrome.action.openPopup but it’ll have several limitations, so a better method would be to use a notification or open a new window via chrome.windows.create. You can also use alert() inside the offscreen document.

    – 




Leave a Comment