Mythical 5th
unread,Feb 25, 2026, 7:39:01 AM (13 days ago) Feb 25Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Chromium Extensions, pullagurla harisha, Simeon Vincent, Chromium Extensions, woxxom
Harisha,
Your listener is added within a function, so it's not clear that it will wake up the service worker or run when the service worker wakes up.
Here's an example to investigate the issue:
manifest.json
```json
{
"name": "Wake Up Service Worker",
"version": "1",
"manifest_version": 3,
"action": {
"default_popup": "popup.html"
},
"permissions": [
"storage"
],
"background": {
"service_worker": "sw.js",
"type": "module"
}
}
```
popup.html
```html
<script src="popup.js" type="module"></script>
```
popup.js
```js
chrome.storage.local.set({timestamp: Date.now()});
```
sw.js
```js
function addListener()
{
chrome.storage.onChanged.addListener(logEvent.bind(null, "in-function"));
}
function logEvent(event)
{
console.log(event);
}
chrome.storage.onChanged.addListener(addListener);
chrome.storage.onChanged.addListener(logEvent.bind(null, "top-level"));
```
When you click the toolbar button once, the console shows "top-level" because of the listener added at the top level (ie. global scope) of the service worker. When the button is clicked again the console will show "top-level" and "in-function" because the listener in the function was added when the service worker first ran. If you wait for the service worker to go to sleep, and then click the toolbar button, the console will only show "top-level". This tells us that the storage listener does wake up a service worker, but it must be added at the top level of the service worker rather than in a function.