2

I made some push notifications for my site, using FCM service. There is code for it (from redux saga):

const reg = yield navigator.serviceWorker.register('/sw.js', {scope: '/'})
const sub = yield reg.pushManager.subscribe({
    userVisibleOnly: true,
    applicationServerKey: push_key,
})
const token = JSON.stringify(sub.toJSON())
console.log(token)

Service worker:

self.addEventListener('push', function(event) {
console.log(event)
if (!self.Notification || self.Notification.permission !== 'granted')
    return

let data = {}
if (event.data)
    data = event.data.json()
const title = data.title || 'Something Has Happened'
const message = data.message || 'Here\'s something you might want to check out.'

event.waitUntil(self.registration.showNotification(title, {
    body: message,
    tag: 'simple-push-demo-notification',
}))
})

I manually init push message by simple python script:

import json
from pywebpush import webpush

t = json.loads('{"endpoint":"https://fcm.googleapis.com/fcm/send/xxx","keys":{"p256dh":"xxx","auth":"xxx"}}')
webpush(t,
    json.dumps({'title': 'hello', 'message': 'world!'}),
    vapid_private_key="xxx",
    vapid_claims={"sub": "mailto:somemail@gmail.com"})

It works totally ok for desktop Chrome and Firefox, showing notifications, but mobile Chrome don't receive any message at all. I tried some push examples and is same story - they just don't show notifications on mobile. I used Chrome 60 on Android 4.2 and Android 7.1.

So, does mobile Chrome supports push notifications? I'm totally confused. That answer says "No" and give some doc link, but i cannot find in that docs something about mobile support or unsupport. That answer says what notifications works only in stock browsers and not in Chrome. But official documentation says (and even show gif!) what all should be ok on mobile!

  • https://goroost.com/try-web-push or https://gauntface.github.io/simple-push-demo/ - push examples that i tried – Ivan Plesskih Sep 22 '17 at 07:31
  • Okay, in my case it silent error was caused by NAT. I have the proxy, which respects by browser, but don't used by google services, so they connect to google apis ignoring proxy, get error and die silently. In normal network all works just ok (at least, on Android 7). – Ivan Plesskih Sep 25 '17 at 12:51
  • On Android 4.4 problem were in Chrome settings in app manager - it hasn't notifications permission. – Ivan Plesskih Sep 28 '17 at 07:44

0 Answers0