Background script stops receiving messages from time to time

493 views
Skip to first unread message

DjSt3rios

unread,
Mar 25, 2023, 5:44:24 PM3/25/23
to Chromium Extensions
Hello everyone, I am facing an issue recently with my background script (MV3). One of the functionalities of my service worker is doing API requests, since doing so from content scripts directly result in CORS errors. I use a simple listener in the background:

chrome.runtime.onMessage.addListener(function (message: IConnectionMessage<any>, sender, sendResponse) {
    if (chrome.runtime.lastError) {
      sendResponse(chrome.runtime.lastError);
      return false;
    }
if (message.command) {
      switch (message.command) {
        case BackgroundConnectorEvents.LOGGED_OUT:
          tasks = undefined;
          sendResponse(true);
          return true;
        case BackgroundConnectorEvents.GET_USER_SETTINGS:
          getUserSettings().then(settings => {
            sendResponse(settings);
          });
          break;
}
return true; });

and I send message through the content scripts/popup using:
chrome.runtime.sendMessage(message);

This works great, the problem is, at random times (I think also hibernating the computer and then waking it up causes problems, or appears more often anyway) the background stops responding. Going to manage extension shows there is a service worker, and it's NOT inactive, and even if it was, I guess receiving a message should wake it up, right?
I am not sure how to debug this further, anyone dealt with this kind of issue before? Any tips would be appreciated.

viktor stolbin

unread,
Mar 26, 2023, 12:57:39 PM3/26/23
to DjSt3rios, Chromium Extensions
What happens if the code inside listener body throws an uncaught exception? Will it be recovered somehow by runtime? Or needs to be re-added?

--
You received this message because you are subscribed to the Google Groups "Chromium Extensions" group.
To unsubscribe from this group and stop receiving emails from it, send an email to chromium-extens...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/chromium-extensions/d6231a26-e886-4c19-ae33-d611ca64ad17n%40chromium.org.

DjSt3rios

unread,
Mar 27, 2023, 5:49:52 PM3/27/23
to Chromium Extensions, viktor stolbin, Chromium Extensions, DjSt3rios

That's a very interesting question, I am not even sure if it can throw an exception, because in most functionality I use catch clauses and return null instead of throwing, but I will just add catch everywhere just in case to see if it makes any difference.

Red ross

unread,
Mar 28, 2023, 4:51:12 AM3/28/23
to Chromium Extensions, DjSt3rios, viktor stolbin, Chromium Extensions
This could be similar to https://groups.google.com/a/chromium.org/g/chromium-extensions/c/Q8_RkcSFi10 but one way to confirm is:
- Check if other listeners are working (setup a chrome.action.onClicked listener and log whenever its triggered. You can try this when the extension is in a broken state to confirm if its just message listeners or other listeners as well -- issue above)

Also curious if you've found a way to repro this with a sample extension (perhaps a subset of your extensions functionality)?

Pavel Aronovich

unread,
Mar 28, 2023, 12:31:53 PM3/28/23
to Chromium Extensions, Red ross, DjSt3rios, viktor stolbin, Chromium Extensions
Add your information to the error:
https://bugs.chromium.org/p/chromium/issues/detail?id=1426461


вторник, 28 марта 2023 г. в 11:51:12 UTC+3, Red ross:
Reply all
Reply to author
Forward
0 new messages