chrome扩展阻止google.co.uk

时间:2014-08-11 00:43:33

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

我已经加载了一个简单的解压缩chrome扩展。关闭所有其他扩展程序。

manifest.js

{
  "manifest_version":2,
  "name":"Etc",
  "description":"Etc",
  "version":"1.0",
  "content_scripts": [{
      "matches" : ["*://*/*"],
      "js": ["contentscript.js"],
      "run_at":"document_end"
  }],
  "background": {
    "scripts": ["background.js"],
    "persistent": false
  },
  "permissions":[
    "tabs", 
    "*://*/*"
  ],
  "browser_action": {
    "default_title": "Idonethis", 
    "default_icon":"icon.png"
  }
}

background.js

chrome.runtime.onMessage.addListener(
  function(request, sender, sendResponse) {
    if (request.greeting == "hello")
      sendResponse({farewell: "goodbye"});
});

contentscript.js

chrome.runtime.sendMessage({greeting:"hello"}, function(response) {
  console.log(response.farewell);
});

在大多数域名(如www.bbc.co.uk)上,邮件传递正常并显示

message contentscript.js:2

但是在www.google.co.uk或uk.yahoo.com上,据我所知,它不传递消息,也不执行任何contentscript.js。这是Chrome扩展安全规范的一部分吗?

EDIT 此代码已修复,可在此处查看 https://github.com/lindaymacvean/test-chrome-ext

1 个答案:

答案 0 :(得分:1)

这可能是因为匹配规则"matches" : ["*://*/"]。您需要将其更改为"matches" : ["*://*/*"],因为目前它只匹配没有路径的选项卡。例如。 http://example.com/会匹配,但http://example.co.uk/foo将不匹配。

相关问题