Google chrome extension 使用chrome扩展在页面加载时自动运行脚本

Google chrome extension 使用chrome扩展在页面加载时自动运行脚本,google-chrome-extension,google-chrome-devtools,Google Chrome Extension,Google Chrome Devtools,如何在加载页面时自动加载脚本 我有这个扩展源: { "browser_action" : { "default_icon" : "icon.png"}, "description" : "Alert on Google Load", "icons" : { "128" : "icon.png" }, "name" : "Auto alert", "version" : "1.0", "content_scripts": [ { "matches": ["h

如何在加载页面时自动加载脚本

我有这个扩展源:

{ "browser_action" : { "default_icon" : "icon.png"},
  "description" : "Alert on Google Load",
  "icons" : { "128" : "icon.png" },
  "name" : "Auto alert",
  "version" : "1.0",
  "content_scripts": [
    {
      "matches": ["http://www.google*"],
      "js": ["myscript.js"],
      "run_at": ["document_end"]
    }
  ],
}
现在myscript.js包括:

alert("hi")
但当我加载google.com时,什么也没发生


非常感谢。

您正在使用的匹配模式(
http://www.google*
)无效。您可以使用通配符(
*
)作为URL的方案、主机或路径部分。您不能将其用作域的一部分

如果要匹配所有Google站点,应使用以下模式:

*://*.google.com/*

您可以在以下文档中阅读有关匹配模式的信息,包括好的和坏的示例:

您是否使用了“https”而不是“http”?