Chrome运行时onSuspend事件不会触发

时间:2018-06-26 10:51:50

标签: events google-chrome-extension runtime suspend

在chrome.runtime.onInstalled事件之后,我插入了一些脚本

chrome.tabs.executeScript(tabId, {file: "jquery-3.2.1.min.js"}, function(){});
chrome.tabs.executeScript(tabId, {file: "mousetrap.min.js"}, function(){});
chrome.tabs.executeScript(tabId, {file: "main.js"}, function(){});
chrome.tabs.insertCSS(tabId, {file: "main.css"}, function(){});

因此,我需要在卸载扩展程序之前删除此脚本并进行清理。对我来说,现在重新加载所有选项卡还是可以接受的。

但是chrome.runtime.onSuspend不会触发。

manifest.js

{
  "manifest_version": 2,
  "name": "....",
  "short_name" : "....",
  "icons": {
    ....
  },
  "version": "....",
  "permissions": [
    "tabs",
    "activeTab",
    "management",
    "*://*/*"
  ],
  "browser_action": {
    ....
  },
  "background": {
    "scripts": ["background.js"],
    "persistent": false
  },
  "content_scripts": [
    {
      "matches": [
        "<all_urls>"
      ],
      "css": [ "main.css" ],
      "js": [
        "jquery-3.2.1.min.js",
        "mousetrap.min.js",
        "main.js"
      ]
    }
  ]
}

background.js

chrome.runtime.onInstalled.addListener(function(details){
    // It works!
});
.....
chrome.runtime.onSuspend.addListener(function() {
    // It does not work
    localStorage["suspend"] = '!!!!';
});
.....

0 个答案:

没有答案