Javascript 关闭扩展时,无法使chrome扩展在后台工作
当弹出窗口打开时,setInterval脚本工作。但是当扩展关闭时,脚本不会在后台运行。代码如下: Manifest.json:Javascript 关闭扩展时,无法使chrome扩展在后台工作,javascript,google-chrome,google-chrome-extension,Javascript,Google Chrome,Google Chrome Extension,当弹出窗口打开时,setInterval脚本工作。但是当扩展关闭时,脚本不会在后台运行。代码如下: Manifest.json: "browser_action": { "default_icon": "iho.png", "default_popup": "index.html" }, "permissions": [ "activeTab", "<all_urls>" ], "background": { "scripts": [ "back
"browser_action": {
"default_icon": "iho.png",
"default_popup": "index.html"
},
"permissions": [
"activeTab", "<all_urls>"
],
"background": {
"scripts": [
"background.js"
]
},
"content_scripts": [
{
"matches": ["*://*/*"],
"js": ["bundle.js"]
}
]
请将问题放在主题上:包括一个与问题重复的完整问题。包括manifest.json、一些后台/内容/弹出脚本/HTML。寻求调试帮助的问题(“为什么此代码不工作?”)必须包括:►想要的行为,►特定的问题或错误,以及►在问题本身中复制它所需的最短代码。没有明确问题陈述的问题对其他读者没有用处。请参阅:“如何创建”,以及。当hello.js没有被引用时,为什么要显示它?bundle.js和index.html在哪里?你到底有什么问题?您似乎正在使用React,但不要加载它。为什么要将bundle.js作为manifest.json
content\u脚本注入,并使用chrome.tabs.executeScript()
也注入它。工具栏弹出窗口环境在关闭时被破坏。2.指定弹出html文件时,browserAction.onClicked将不起作用。3.请务必阅读扩展概述,尤其是架构文章。
var MainApp = React.createClass({
submitForm: function (e){
event.preventDefault();
function myCallback(){
alert("hi there")
}
window.setInterval(myCallback, 8000);
},
render: function () {
return (
<div>
<button onClick={this.submitForm}> click me! </button>
</div>
)
}
})
chrome.browserAction.onClicked.addListener(function (tab) {
chrome.tabs.executeScript(null, {file: "bundle.js"});
});