setInterval脚本在弹出窗口打开时有效。但是当扩展程序关闭时,脚本不会在后台运行。这是代码:
的manifest.json:
"browser_action": {
"default_icon": "iho.png",
"default_popup": "index.html"
},
"permissions": [
"activeTab", "<all_urls>"
],
"background": {
"scripts": [
"background.js"
]
},
"content_scripts": [
{
"matches": ["*://*/*"],
"js": ["bundle.js"]
}
]
hello.js
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>
)
}
})
background.js
chrome.browserAction.onClicked.addListener(function (tab) {
chrome.tabs.executeScript(null, {file: "bundle.js"});
});