如果在请求中将检测到取消加载页面"某些单词"镀铬扩展

时间:2015-11-20 13:36:28

标签: javascript google-chrome google-chrome-extension

当客户端搜索内容并在此请求中找到某个单词时,如果存在页面加载将被停止(搜索将被取消),如何捕获搜索请求?

更新

的manifest.json:

  "background": {
    "scripts": ["background.js"]
  }
  "permissions": [
    "tabs",
    "webRequest",
    "webNavigation",
    "management",
    "http://*/*",
    "https://*/*",
    "*://*.google.com/",
    "webRequestBlocking",
    "<all_urls>"
  ]
}

background.js:

chrome.webRequest.onBeforeRequest.addListener(
  function(details) {
    return {cancel: details.url.indexOf("://salom/") != -1};
  },
  { urls: ["<all_urls>"] },
  ["blocking"]
);

1 个答案:

答案 0 :(得分:-1)

"background": { "scripts": ["background.js"] } "permissions": [ "tabs", "webRequest", "webNavigation", "management", "http://*/*", "https://*/*", "*://*.google.com/", "webRequestBlocking", "<all_urls>" ] } 它是明显的json和background.js是

chrome.webRequest.onBeforeRequest.addListener(
  function(details) {
    return {cancel: details.url.indexOf("://salom/") != -1};
  },
  { urls: ["<all_urls>"] },
  ["blocking"]
);