I develop Chrome extension.
I try to add event listener to chrome.runtime.onSuspend
, but it is never called.
I use the following code, but localStorage is not modified and there is no log messages in the console also (I use --enable-logging --v=1
to save log messages to the file).
chrome.runtime.onSuspend.addListener(function() {
localStorage["suspend"] = new Date();
console.log("On suspend");
});
Test box: WinXP SP3 x86 with Chrome 28.0.1500.72 m
I've created test extension to easily reproduce this issue:
manifest.json
{
"manifest_version": 2,
"name": "Chrome onSuspend test",
"version": "1.0",
"background": {
"scripts": ["background.js"] }
}
background.js
chrome.runtime.onSuspend.addListener(function() {
localStorage["suspend"] = new Date();
console.log("On suspend");
});
The onSuspend
event is only triggered when the event page becomes inactive.
Because you didn't declare persistent: false
in your manifest file, the background page is a background page, not an event page. Consequently, the page will never become inactive, and the onSuspend
event will never be triggered.
If you wish to turn your background page in an event page, use
...
"background": {
"scripts": ["background.js"],
"persistent": false
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With