To reproduce this error:
Manifest version 3
In popup (“action”) a button click invokes chrome.runtime.sendMessage
.
The background script is listening to it via chrome.runtime.onMessage.addListener
and will open some extension page (i.e. settings page or contact page) in the callback.
But:
The promise returned by chrome.runtime.sendMessage
will be rejected with "Could not establish connection. Receiving end does not exist." if the background went idle/stopped running and its event page got terminated, so that the user has to click the popup button twice (since the first attempt will trigger the background and re-activate it).
How should this be dealt with?
As a workaround I could always try a second time to send the message(?) - but I’m sure there’s a saner way to handle this issue…
I think more generally speaking the issue is with not having persistent background scripts anymore in v3 and the lack of experience on how to handle non-persistent bg scripts.