【发布时间】:2019-06-22 16:06:39
【问题描述】:
我想在浏览器中单击我的扩展程序图标,并在我当前在浏览器中选择的网页/选项卡的控制台中显示“测试”。
manifest.json:
{
"name": "some name",
"version": "1.0",
"description": "some description",
"manifest_version": 2,
"permissions": ["storage", "tabs", "activeTab"],
"browser_action": {
"default_title": "hello!",
"default_popup": "popup.html",
"default_icon": "icon.png"
},
"background": {
"scripts": ["background.js"],
"persistent": true
}
}
background.js:
chrome.browserAction.onClicked.addListener(function(){
chrome.tabs.executeScript(null, {
code: "test"
})
我已使用“选项卡”和“活动标签”来获取权限,因为我相信这些是运行此代码所必需的。
如果我单击扩展程序,它不会显示错误,但它也不会在我所在网页的控制台日志中显示“测试”。
从我提供的代码来看,这有什么明显的原因吗?
【问题讨论】:
-
用
"console.log('test')"替换"test" -
我偶然发现了这个问题所在:stackoverflow.com/questions/18766886/…
-
当有 popup.html 时它可能不允许 onClicked 事件,因为该事件可以放在 popup.js 中。
标签: google-chrome-extension browser-action