Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

189
Visualizações
Run web extension's service worker on browser open (Chrome)

I am building a web extension (Chrome) that checks if the external's API changed. This should be happening periodically (e.g. every 10 mins) and in the background. The plan is to have a service worker that would fire these requests, and replace extension's icon when a change in the response was detected. I have a working code that does exactly that, but I am unable to persist the service worker, and make it run on browser load (i.e. moment when the window opens). I managed to use message API, but that requires the user to click the extension button to open it and only then the extension would continuously run in the background.

This is my service worker code:

const browser = chrome || browser;

self.addEventListener("message", async (event) => {
    if (event.data && event.data.type === 'CHECK_FOR_NEW_RESOURCES') {
        communicationPort = event.ports[0];

        const compareStructures = setInterval(async () => {
            const currentStructure = await getStructure(event.data.baseURL + 'webservice/rest/server.php', event.data.token);
            const {curr, newResources } = findDifferences(event.data.structure.base, currentStructure);
            if(newResources > 0) {
                communicationPort.postMessage({different: true, structure: curr, newResources,
                    time: new Date().toISOString()});
                browser.action.setIcon({ path: { '48': event.data.newResourcesIcon } });

                clearInterval(compareStructures);
            } else {
                communicationPort.postMessage({ different: false, time: new Date().toISOString() });
                browser.action.setIcon({ path: { '48': event.data.noNewResourcesIcon } });
            }
        }, 900000);
    }
});

const getStructure = async (url, token) => {
// Uses fetch() to get the resources
   ...
};

const findDifferences = (newStructure, oldStructure) => {
   ...
};

If it is not possible, what are the viable options to achieve my desired design? Could reverting to manifest ver. 2 help?

Hopefully my description makes sense, and I think it is possible, as I have seen extensions send notifications when the browser is opened.

about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda