我正在尝试为我的chrome扩展程序创建一个开/关切换。但是,它一直在说无法读取点击时我的浏览器操作?这就是我到目前为止所拥有的...
清单
{
"manifest_version": 2,
"name": "Spatial Intelligence",
"version": "0.1.0",
"description": "Dope vibes for all",
"chrome_url_overrides" : {
"newtab": "myNewTabPage.html"
},
"background": {
"scripts": ["background.js"],
"persistent": true
},
"browser_action": {
},
"content_scripts": [{
"run_at" : "document_end",
"css": ["styles.css"],
"js": ["content.js"],
"matches": ["<all_urls>"]
}]
}
背景
var enable =false;
chrome.browserAction.onClicked.addListener(function (tab) {
enable ?= enable false : true;
if(enable){
//turn on...
chrome.browserAction.setIcon({ path: 'https://i.ibb.co/XCKg9qd/pizza.png' });
chrome.browserAction.setBadgeText({ text: 'ON' });
chrome.tabs.executeScript(null, { file: 'content.js' });
}else{
//turn off...
chrome.browserAction.setIcon({ path: 'https://i.ibb.co/hFg555J/pizza-bw.png'});
chrome.browserAction.setBadgeText({ text: 'OFF' });
}
});
有人对如何解决此问题有任何见解吗?另外,我是否在正确的轨道上进行了开/关切换?