Stanko
Stanko

Reputation: 4465

onBeforeRequest not triggering: expected 'object' but got 'array'

I'm trying to let onBeforeRequest trigger but it doesn't trigger once.

The background page console displays an error:

Invalid value for argument 1. Expected 'object' but got 'array'

manifest.json:

{
  "name": "Blocker",
  "version": "1.0",
  "description": "Blocks all websites",
  "permissions": ["webRequest", "webRequestBlocking", "<all_urls>"],
  "background": {
    "scripts": ["background.js"]
  },

  "manifest_version": 2
}

background.js:

chrome.webRequest.onBeforeRequest.addListener(
  function(info) {
    console.log("TRIGGERED")
    return {cancel: true};
  },
  // extraInfoSpec
  ["blocking"]);

What am I doing wrong or am I just expecting something onBeforeRequest isn't supposed to do? For example I expect the following:

  1. I enter url into address bar
  2. I press enter
  3. onBeforeRequest triggers before website is shown
  4. User gets message that website is blocked

Upvotes: 0

Views: 187

Answers (1)

woxxom
woxxom

Reputation: 73616

According to the documentation:

In addition to specifying a callback function, you have to specify a filter argument

chrome.webRequest.onBeforeRequest.addListener(
    function(info) {
        console.log(info);
        return {cancel: true};
    }, {
        urls: ['<all_urls>'],
    },
    ['blocking']
);

Upvotes: 1

Related Questions