I'm developing a browser extension which blocking calls to specific url's upon client demand.
The url's needs to be blocked are passing as "localStorage" arguments.
This is my extension code:
function logURL(requestDetails) {
console.log("Loading: " + requestDetails.url);
return {cancel: true};
}
browser.webRequest.onBeforeRequest.addListener(
logURL,
{urls: (localStorage.getItem('block_urls') ? localStorage.getItem('block_urls') : ["https://default/default"] )},
["blocking"]
);
What I expect to happen is that before each request, urls will be read from localStorage and blocked accordingly. If localStorage is null, I have a default url pattern (which basically does nothing).
What actually happens is that the filter param (urls) is called only once (when the extension is loaded) and not before every request.
Is there any way to dynamically change the filter for this event?
Thanks for the helpers.
There are two ways to do this: