这个问题想要知道chrome扩展中背景脚本和内容脚本的区别。当我在两个脚本中记录chrome对象时,发现它们的对象不同。
用例
我想在单击图标时将我的JavaScript注入页面,因此在manifest.json
中添加了一个内容脚本,但是我无法在内容脚本中监听图标单击事件。
内容脚本中的chrome对象中未定义chrome.browserAction。
问题
如何在内容脚本中监听单击事件?能同时包含背景脚本和内容脚本吗?
这是我的manifest.json:
{
"name": "First Plugin Testing",
"version": "1.0",
"manifest_version": 2,
"description": "Trying hands on first extension",
"background": { "scripts": ["background.js"] },
"browser_action": {
"default_icon": "icon.png"
},
"permissions": [
"tabs", "http://*/*", "https://*/*"
],
"content_scripts": [
{
"matches": ["http://*/*"],
"js": ["temp.js"]
}
]
}