我正在开发chrome扩展程序,当用户在浏览器页面中选择一些单词时,我需要以下功能,我想触发一个事件,这很简单,它非常像Google Translate Google Chrome扩展程序,它显示弹出窗口选择单词时。
我试过以下
background.js
chrome.runtime.onMessage.addListener(function (message, callback) {
if (message.data == "getSelection")
console.log(message.data);
});
清单
{
"permissions": [ "activeTab", "<all_urls>", "declarativeContent", "storage" ],
"browser_action": {
"default_popup": "popup.html",
"default_icon": {
"16": "images/cdicon.png"
}
},
"background": {
"scripts": [ "background.js" ],
"persistent": true
},
"content_scripts": [
{
"matches": [ "<all_urls>" ],
"js": [ "selection.js" ],
"run_at": "document_start",
"all_frames": true
}
]
}
问题是在选择任何单词时没有触发事件