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

298
Visualizações
Is there any synchronous (non-async) storage API for background service worker in Chrome Extension Manifest V3?

We are in process of upgrading many Chrome extensions to Manifest version 3. Many of them has a background script that use localStorage which is not available in Service Worker. I know chrome.storage or IndexedDB APIs are valid replacement but they are asynchronous and it would takes a lot of effort for some extensions to be changed into async. So my problem can be solved by either:

  • Find a storage API that is NOT async which I am not aware of.

  • Question: Find a pattern that can quickly and reliably upgrade synchronous code in many places into asynchronous.

I believe the 2nd attempt is the most sensible one. However so many places have methods like this (just example) which makes upgrading difficult and also prone to error due to missing Promise/await.

// Background
localStorage["key"] = true;

if (localStorage["key2"]) {
    // Do stuff
}

// Foreground/Popup/Content Script
if (localStorage["key"]) { /* Do Something */ }
if (localStorage["key2"]) { /* Do Something Else */ }
localStorage["key3"] = "My Value";

There are a few nice extensions with these code, which are easy to upgrade:

chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
    if (request.method == "getLocalStorage") {
        sendResponse({ data: localStorage[request.key] });
    }
});

Which I simply need to change the message handler to async since the receiving end is already callback-based. Unfortunately, every extension is very different and there is no standard way of doing it.

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