【问题标题】:Auto run script on page load with chrome extension使用 chrome 扩展在页面加载时自动运行脚本
【发布时间】:2012-08-13 02:28:18
【问题描述】:

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

我有这个扩展源:

{ "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 时,什么都没有发生。

非常感谢。

【问题讨论】:

  • 会不会是你使用'https'而不是'http'?

标签: google-chrome-extension google-chrome-devtools


【解决方案1】:

您使用的匹配模式 (http://www.google*) 无效。您可以使用通配符 (*) 作为 URL 的 schemehostpath 部分。您不能将其用作 的一部分。

如果你想匹配所有的谷歌网站,你应该使用这个模式:

*://*.google.com/*

您可以在以下文档中阅读有关匹配模式的信息,包括好的和坏的示例:http://developer.chrome.com/extensions/match_patterns.html

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多