I have an array of URLs in local storage, and I am trying to block those. All URLs except https://www.youtube.com/ are blocked successfully.
Even when refreshing the page in case of https://www.youtube.com/, it is logging to the console "entered" that is inside the if statement of blockListener.
then even after this is not blocking the request.
Why is happening so?
code is here.......
function blockListener(details) {
var sites = JSON.parse(localStorage.getItem(sitesToBeBlockedKey));//got sites array
console.log(sites.includes(details.url));
if(sites.includes(details.url)){
console.log('entered');
return {
cancel: true
};
}else{
return {
cancel: false
};
}
}
function checkBlockRequest(){
console.log('blocking start');
chrome.webRequest.onBeforeRequest.addListener( blockListener, { urls: ["<all_urls>"], types: [ 'main_frame' ] }, ['blocking'] );
});
}
checkBlockRequest();//called