所以只想在页面上计算标签并在徽章上显示
content.js
document.body.addEventListener('DOMContentLoaded', e => {
var a=document.getElementsByTagName('a').length;
chrome.runtime.sendMessage(a)
});
background.js
chrome.runtime.onMessage.addListener(message => {
var b=message
chrome.browserAction.setBadgeText({"text":b.toString()})
});
manifest.json
{
"manifest_version": 2,
"name": "The Chrome Link Counter",
"version": "1.0",
"description": "counter",
"icons": {
"48": "icons/icon_default.png"
},
"content_scripts": [
{
"matches": ["<all_urls>"],
"all_frames": true,
"js": ["content/main.js"]
}
],
"background": {
"scripts": ["background/main.js"]
},
"options_ui": {
"page": "options/main.html",
"chrome_style": true
},
"browser_action": {
"default_popup": "options/main.html",
"chrome_style": true,
"default_icon": {
"16": "icons/icon_default.png"
}
},
"web_accessible_resources": ["icons/icon.png", "icons/check.png"],
"permissions": ["storage", "webRequest","tabs"]
}
但是当我尝试这里缺少的东西时什么都没有发生?
编辑:还添加了manifest.json