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",
}
}