2017-03-02 57 views
0

我想讓onBeforeRequest觸發器,但它不會觸發一次。onBeforeRequest不觸發:預期的'對象',但得到'數組'

background page console顯示錯誤:

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"]); 

我在做什麼錯還是我我只是e xBecting onBeforeRequest不應該做什麼?例如,我想到了以下幾點:

  1. 我輸入網址到地址欄
  2. 我按enter鍵
  3. onBeforeRequest觸發之前的網站顯示
  4. 用戶獲取網站被封鎖消息
+0

是的,你是對的,我得到以下錯誤:http://prntscr.com/ef6pij – Stanko

回答

1

根據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'] 
); 
相關問題