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.