www.google.com上的Chrome扩展程序

时间:2018-04-23 05:59:11

标签: google-chrome-extension

在学习chrome扩展时,我尝试创建一个简单的chrome扩展,其内容脚本包含一个警告语句。这在我打开www.google.co.in时工作正常,我收到警报但是当我打开www.google.com时,我没有收到警报。附上截图。我错过了什么?

清单:

{
  "manifest_version": 2,
  "name": "My Cool Extension",
  "version": "0.1",
  "background": {
    "scripts": ["coolBackground.js"]
  },
  "content_scripts": [
    {
      "all_frames" : true,
      "matches": ["\u003Call_urls\u003E"],
      "js": ["coolContent.js"]    }
  ],
  "browser_action": {
    "default_icon": "icon.png",
    "default_popup": "popup.html"
  }
}

popup.html:

<!doctype html>
<html>
    <head>
        <title>Hello World</title>
        <script src="coolBackground.js"></script>
        <link rel="stylesheet" type="text/css" href="popup.css" />
    </head>
    <body>
        <h1 id="greeting">Hi!</h1>
        <input id="name" type="text" />
    </body>
</html>

coolContent.js:

alert("Hello world");

coolBackground.js:

console.log("background");

screenshot of google.com screenshot of google.in

1 个答案:

答案 0 :(得分:0)

在manifest.json中添加适当的权限。见下文一个例子。

"permissions": [
    "*://*/*"
 ],
 "content_scripts" : [
    {
        "matches" : ["*://*/*"],
   .....