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

144
Visualizações
Keeping FileSystemDirectoryHandle object in Chrome Extension

I'm working on Chrome extension. Inside popup I can run window.showDirectoryPicker(), which returns object of type FileSystemDirectoryHandle.

My problem is that after changing tab in browser popup is automatically closed, so object is destroyed.

My question is: is there any way to pass this object to any other context (for example to ServiceWorker or other window)?

Or if it is not possible, is there any way for invoking window.showDirectoryPicker() inside extension's ServiceWorker?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

  • Send the handle via the standard service worker messaging from an extension page:

    (async () => {
      const handle = await window.showDirectoryPicker();
      const swr = await navigator.serviceWorker.ready;
      swr.active.postMessage(handle);
    })();
    

    In the service worker, use self.onmessage = e => { console.log(e) };
    Note that it'll print in the background devtools.

  • Copy from one extension page to another extension page that is currently open via getViews:

    chrome.tabs.create({url: 'another.html'}, async tab => {
      await new Promise(resolve => {
        chrome.tabs.onUpdated.addListener(function onUpdated(tabId) {
          if (tabId === tab.id) {
            chrome.tabs.onUpdated.removeListener(onUpdated);
            resolve();
          }
        });
      });
      const wnd = chrome.extension.getViews({tabId: tab.id})[0];
      wnd._handle = handle;
      // `another` page will see a global variable `window._handle`
    });
    
  • Send via BroadcastChannel within the extension pages or the service worker.

  • Save it in IndexedDB and reuse it in the future.

about 4 years ago · Juan Pablo Isaza Relatório
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