当扩展程序关闭时,无法使chrome扩展在后台运行

时间:2016-12-31 23:03:28

标签: 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": [
      "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"});
});

0 个答案:

没有答案