chrome extension always show "service worker inactive" after browser restart if manifest is MV3

Viewed 1518

i am using the latest chrome: Version 100.0.4896.60 (Official Build) (64-bit) on win 10 pro

when i install an extension all works fine.

when i close chrome and reopen, the extensions no long work. the extensions tab shows for all extensions: "worker service (inactive)"

after click on the reload button of the extension all is ok.

i also tested it with:

https://github.com/GoogleChrome/chrome-extensions-samples/tree/main/examples/hello-world

to make sure that this could be to some settings, i uninstalled chrome, removed all chrome files and reinstalled it.

the issue persists.

friends of mine do not seem to have this issue with the same chrome version.

any suggestions on how to resolve this ?

here the code:

    "use strict";

async function sendRequest(request, sendResponse) {
  try {
    const startTime = Date.now();
    const response = await fetch(request.url, request.options);
    const time = Date.now() - startTime;
    const body = await response.text();
    const headers = [...response.headers].map((el) => ({
      key: el[0],
      value: el[1],
    }));
    sendResponse({
      status: response.status,
      body,
      headers,
      time,
    });
  } catch (err) {
    sendResponse({
      err: err.message
    });
  }
}

chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
  chrome.storage.sync.get("host", ({ host }) => {
    if (host === sender.tab.url) {
      if (request.type === "send-request") {
        sendRequest(request, sendResponse);
      } else if (request.type === "ping") {
        sendResponse();
      } else {
        console.log("bad request type", request.type);
      }
    } else {
      console.log("host not correct", host, sender.tab.url);
    }
  });
  // NOTE: return value required to keep port open for async response
  return true;
});

chrome.webNavigation.onBeforeNavigate.addListener(() => {
  console.info("service is up 2");
});

chrome.webNavigation.onHistoryStateUpdated.addListener((details) => {
  console.log('service is up');
});

1 Answers
Related