1

I am trying to build a simple chrome extension that will block a list of websites. At the moment I have this:

    function logURL(requestDetails) {
      console.log("Loading: " + requestDetails.url);
      alert(1);

    }

    chrome.webRequest.onBeforeRequest.addListener(
      logURL,
      {urls: ["*://*.google.com/*"]}
    );

When I go to google I get an alert. When I close the alert I get another one and another one and they keep coming.

When I take out the

alert(1);

I don't get any alerts but I also do not get any console logs which I would expect.

Any ideas?

P.S I'm a junior developer and just learning so apologies if this is really simple, I would appreciate a detailed reply as it will help me develop my skills.

modusTollens
  • 397
  • 7
  • 23
  • You get many alerts because many requests happen. You can track that in Network tab of developer tools. I think you have opened developer tools on the google.com tab, but you need to open the developer tools on the extension's background page. Go to chrome extension's page, check developer mode (at top right corner). Now take a look at the extension card and click `background page`. – Granga Nov 29 '18 at 23:51
  • @Granga ohhhhhh there is a different console for this. :( I didnt know. That you. – modusTollens Nov 30 '18 at 00:38
  • Possible duplicate of [Where to read console messages from background.js in a Chrome extension?](https://stackoverflow.com/questions/10257301/where-to-read-console-messages-from-background-js-in-a-chrome-extension) – wOxxOm Nov 30 '18 at 06:08

0 Answers0