Chrome扩展如何删除chrome.webRequest.onBeforeRequest中的监听器 [英] Chrome extension How to remove a Listener on chrome.webRequest.onBeforeRequest
本文介绍了Chrome扩展如何删除chrome.webRequest.onBeforeRequest中的监听器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正尝试在Google Chrome浏览器扩展程序中移除此侦听器以阻止网址,但我不知道该如何操作! $ b
chrome.webRequest.onBeforeRequest.addListener(
function(info){
console.log(截获的聊天:+ info.url);
return {cancel:true};},
{url:[https:// sampleUrl / *]},
[blocking ]
);
解决方案
问题的解决方案是创建一个命名函数而不是一个匿名函数
$ b $ pre $ var myfunction = function(info){
//指令
return {取消:true}; };
并将其替换为代码中的变量:
chrome.webRequest.onBeforeRequest.addListener(
myfunction,
{url:[https:// sampleUrl / *]},
[blocking]
);
如果我想删除我使用的侦听器:
chrome.webRequest.onBeforeRequest.removeListener(myfunction);
i am trying to remove this Listener in a google chrome extension for blocking urls, but i don't know how!
chrome.webRequest.onBeforeRequest.addListener(
function(info) {
console.log("Chat intercepted: " + info.url);
return {cancel: true}; },
{urls: ["https://sampleUrl/*"]},
["blocking"]
);
解决方案
The solution to the problem is to create a named function instead of an anonymous function
var myfunction= function (info) {
//Instructions
return {cancel: true}; };
and replace it as a variable in the code :
chrome.webRequest.onBeforeRequest.addListener(
myfunction,
{urls: ["https://sampleUrl/*"]},
["blocking"]
);
if i want to remove that listener i use :
chrome.webRequest.onBeforeRequest.removeListener(myfunction);
这篇关于Chrome扩展如何删除chrome.webRequest.onBeforeRequest中的监听器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文