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

292
Visualizações
chrome extension : webrequest await async call before block

In manifest v2, I am trying to force the onBeforeRequest listener to wait for an asynchronous call before the evaluation of a test condition that decides whether to block the request or let it go.

The documentation and topics i came accross seems conflicting, some say that this feature is not supported within webRequest, while others suggest there could be workarounds.

The most promising one i found so far but unfortunately didn't quite work in my case, came from this post : Use asynchronous calls in a blocking webRequest handler

Is there a possible idea to circumvent this issue ?

chrome.webRequest.onBeforeRequest.addListener(
    function() {
      chrome.tabs.query({active:true,windowType:"normal", currentWindow: true},function(tab){
        for(const [key, value] of Object.entries(inputMaps[tab[0].id][Object.keys(inputMaps[tab[0].id])[0]])){
          chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
            // Async call to content_script will update the testMap[curTabId] 
            chrome.tabs.sendMessage(tabs[0].id, 
            {
              text: "aadAuth",
              usr: Object.keys(inputMaps[tabs[0].id])[0],
              pass: value
            })  
          });
        }
      });  
     // Need to make sure this executes after the reception of async call response
     // Impossible to block the request from within the async response callback method.   
     if(testMap[curTabId]){
       return {cancel: true};
     }else{
       return {}
     }
              
    },
    {urls: ["<all_urls>"]},
    ["blocking"]
);

Extract of the manifest :

{
  "manifest_version": 2,
  "background": {
    "service_worker": "background.js"
  },
  "permissions": [
    "storage",
    "activeTab",
    "tabs",
    "webRequest",
    "webRequestBlocking",
    "<all_urls>"
  ],
  "browser_action": {
    "default_popup": "popup.html",

  }
}
about 4 years ago · Santiago Gelvez
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