Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

278
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!