在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"] = '!!!!';
});
.....