gpt4 book ai didi

javascript - onBeforeRequest 未触发 : expected 'object' but got 'array'

转载 作者:行者123 更新时间:2023-12-03 04:53:14 25 4
gpt4 key购买 nike

我试图让 onBeforeRequest 触发,但它不会触发一次。

background page console显示错误:

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

ma​​nifest.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"]);

我做错了什么或者我只是期待 onBeforeRequest 不应该做的事情?例如,我期望以下内容:

  1. 我在地址栏中输入网址
  2. 我按 Enter
  3. onBeforeRequest 在网站显示之前触发
  4. 用户收到网站被屏蔽的消息

最佳答案

根据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']
);

关于javascript - onBeforeRequest 未触发 : expected 'object' but got 'array' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42558719/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com