Chrome webRequest listening to only user entered URLs

Viewed 1702

I'm making a Chrome extension that only allows users to access websites that are on a given whitelist. chrome.webRequest.onBeforeRequest is perfect for intercepting and examining the URLs but the problem I am having is that it examines all incoming URLs including when a webpage is trying to load resources. I want it to only examine user entered URLs and if that URL is on the whitelist I want it to allow that webpage to load any resources it needs, regardless of if they are on the whitelist or not.

Here is my code for the listener.

    chrome.webRequest.onBeforeRequest.addListener(
      function(info) {
        console.log("URL: " + info.url);
        var pageURL = info['url'];
        let mngwlst = new ManageWhitelist();
        var whitelist = mngwlst.getWhitelist();
        if(whitelist == null) mngwlst.setWhitelist([]);
        var denyRequest = false;
        var denyRequest = monitor.ExamineWhitelist(pageURL, whitelist);
        console.log(denyRequest);
        return {cancel: denyRequest}
    },

    {
        urls: [
        "<all_urls>"
        ],
    },

    ["blocking"]);

monitor.ExamineWhitelist(pageURL, whitelist) will return true or false depending on if the URL is or isn't on the whitelist.

2 Answers
Related