【问题标题】:Inject a div with content script not working注入内容脚本不起作用的 div
【发布时间】:2012-11-03 22:40:17
【问题描述】:

我对看似非常简单的事情感到困惑。 我试图在用户访问的每个页面中注入我自己的 div,在 google chrome 扩展中。 我查看了网络上的示例,但似乎没有什么对我有用:s

这是我的 manifest.json

{
"name": "My extension",
"version": "1.0",
"permissions": [
    "http://*/*", "tabs", "https://*/*"
],
"browser_action": {
    "default_title": "My extension",
    "default_icon": "icon.png"
},
"manifest_version": 2,
"content_scripts": [
  {
    "matches": ["http://*/*", "https://*/*"],
    "js": ["test.js"],
    "run_at": "document_end",
    "all_frames": true
  }
]
}

还有我的 test.js

var newdiv = document.createElement('div'); 
newdiv.setAttribute('id','this_is_my_own_div');
document.body.appendChild(newdiv);

但我在源代码中一无所获... 我的 div 没有创建。 如何检查我的 test.js 是否正在运行?我不明白为什么它是和别人一起工作而不是和我一起工作:s 任何帮助不胜感激!

【问题讨论】:

    标签: dom google-chrome-extension content-script


    【解决方案1】:

    试了一下:

    "browser_action": { "default_title": "My extension", "default_icon": "icon.png" },
    

    代替:

    "browser_action": { "name": "My extension", "icons": ["icon.png"] }, 
    

    【讨论】:

    • 它工作尝试“browser_action”:{“default_title”:“我的扩展”,“default_icon”:“icon.png”},而不是“browser_action”:{“name”:“我的扩展", "图标": ["icon.png"] },
    • 我可能在这里遗漏了一些东西......这也不起作用。例如,amazon.com 的源页面中仍然没有“this_is_my_own_div”...
    • 嗯,显然,它正在我同事的 Mac 上运行。我在 Windows 8 上运行版本 23.0.1271.64 m,也许这就是为什么......虽然奇怪......
    猜你喜欢
    • 2012-04-04
    • 1970-01-01
    • 1970-01-01
    • 2016-12-23
    • 1970-01-01
    • 2015-04-06
    • 1970-01-01
    • 2013-02-26
    相关资源
    最近更新 更多