Search code examples
pushmessagefirefox-os

How to use external file to handle push notifications in FirefoxOS?


I'm trying to get working Push Notifications on my FirefoxOS App. While it's working as expecte when the app is opened, when the app is closed it not works anymore. I thought that was the app is trying to execute the whole app instead only the handler so I'm trying to use the messages section on the manifest.webapp.

"messages": [
    { "push": "/push/push.html" },
    { "push-register" : "index.html" },
    { "notification": "index.html" }
],

My code on /push/push.html is:

<script>

navigator.mozSetMessageHandler('push', function () {
  c = new Notification( 'testing 4' );
});
</script>

But it seems that's not loading the file when the push message arrives the device. For me, it doesn't seems to be a path problem, because I tried everything (launch path is /index.html, and I've tried moving push.html to the root and put /push.html).

Any clue?


Solution

  • Well, after hours trying it and a lot of research, seems that's not possible to get working the push in another page.

    Remember: when a user selects an app, the lauch_path is displayed. There’s a bug right now that restricts push notifications to the page that calls register(). Right now, what’s under “messages” doesn’t matter if it’s not the same as the page that calls register(). Keep your eye on that bug if you want to know when it’s fixed. For now, it’s probably a good idea to keep your app to one page and use dynamic formatting to present info back to the user.

    Firefox OS v1.1 only allows the page that registers for Push Notifications to recieve them, so you cannot have / call navigator.push.register() and have /push.html be the receiver that uses navigator.mozSetMessageHandler().

    More info about the bug: https://bugzilla.mozilla.org/show_bug.cgi?id=800431 [^] https://bugzilla.mozilla.org/show_bug.cgi?id=897112 [^]