如何阻止一些带有chrome扩展名的网址

时间:2015-09-01 20:01:12

标签: javascript google-chrome-extension

我正在尝试制作自己的Chrome扩展程序 阻止facebook的“看到”和“打字”状态。 但似乎我的方式不起作用

有人可以帮我找到我的错误吗?

的manifest.json

{
    "name": "Block Seen Typing",
    "description": "Block Seen",
    "version": "1.0",
    "manifest_version": 2,
    "background": {
        "scripts": [
            "background.js"
        ]
    },
    "permissions": [
        "webRequest",
                    "*://facebook.com/*",
            "*://www.facebook.com/*",
        "webRequestBlocking"
    ]
}

background.js

chrome.webRequest.onBeforeRequest.addListener(
{
    urls: [
        "https://www.facebook.com/ajax/messaging/typ.php", "https://www.facebook.com/ajax/mercury/mark_seen.php", "https://www.facebook.com/ajax/mercury/change_read_status.php"                    // here you put the URL that you want to block.
    ],
    types: ["main_frame", "sub_frame", "stylesheet", "script", "image", "object", "xmlhttprequest", "other"]
},
["blocking"]);

通常我想知道如何阻止我想要的任何网络请求。

1 个答案:

答案 0 :(得分:1)

看起来你忘了为侦听器实际包含任何代码。试试这样的事情

chrome.webRequest.onBeforeRequest.addListener(function(d){
  return {cancel:true};
},{urls:["https://www.facebook.com/ajax/messaging/typ.php",
         "https://www.facebook.com/ajax/mercury/mark_seen.php",
         "https://www.facebook.com/ajax/mercury/change_read_status.php"]},
  ["blocking"]);