![](/img/trans.png)
[英]How to use chrome.identity.getProfileUserInfo in chrome.webRequest.onBeforeRequest?
[英]Chrome extension How to remove a Listener on chrome.webRequest.onBeforeRequest
我正在尝试在Google chrome扩展程序中删除此侦听器以阻止URL,但我不知道如何!
chrome.webRequest.onBeforeRequest.addListener(
function(info) {
console.log("Chat intercepted: " + info.url);
return {cancel: true}; },
{urls: ["https://sampleUrl/*"]},
["blocking"]
);
该问题的解决方案是创建一个命名函数而不是匿名函数
var myfunction= function (info) {
//Instructions
return {cancel: true}; };
并将其替换为代码中的变量:
chrome.webRequest.onBeforeRequest.addListener(
myfunction,
{urls: ["https://sampleUrl/*"]},
["blocking"]
);
如果我想删除该监听器,我使用:
chrome.webRequest.onBeforeRequest.removeListener(myfunction);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.