I have a simple extension running in background mode (basically the sample chrome client gcm code). When I send a gcm message to my extension while chrome is running the message is received fine. If I then close chrome, send gcm messages to the same reg id, then re-start chrome, the messages are not received. One would expect onMessage to be called when the extension starts (and the onMessage listener is added). Why is this not the case?
-
hi, did you end up finding a solution for this issue ? – jacob Nov 07 '18 at 21:43
1 Answers
Background pages must be registered in the extension manifest. If you need to specify HTML in your background page, you can do that using the page property:
manifest.json
{
"name": "My extension",
...
"background": {
"page": "background.html"
},
...
}
In addition to that, since I'm not sure what you already have in your code, I might as well add about service worker too. As discussed in Implementing Push Messaging for Chrome, registering a service worker is needed to implement push messages for the web.
The reason for this is that when a push message is received, the browser can start up a service worker, which runs in the background without a page being open, and dispatch an event so that you can decide how to handle that push message.
To fully understand the function of a service worker, you may go through Introduction to Service Worker and solution given in this SO post - GCM messages not getting delivered to Chrome Packaged Apps(offline mode) might work for you too.
-
It's a background script, with "background" permission set in the manifest. I'm not interested in using service worker as it's not a web page or app, it's an extension, and I'm only using gcm. The other link does not help. You can check it out at linkymclinkface.com and see the extension code. If browser is open messages are received fine. If browser closed and messages are sent to it, when the browser re-opens, the "offline" messages are not received. The onMessage event does not fire for "offline" gcm messages when the browser starts up. – 2fours May 31 '16 at 15:30