Missing push data on Android's PWA but not on Desktop

旧街凉风 提交于 2019-12-12 00:37:07

问题


UPDATE: Updating Chrome from 58 to 76 has resolved the issue. According to this link Chrome v50+ supports payload which has not been the case here. Either there's a bug / issue with Chrome 58 or there's a bug somewhere in the code. Still interested to learn which.

I'm following the same procedure to send my push message for both Mobile and Desktop.

Server (node.js):

const webpush = require('web-push')

const vapidKeys = {
  publicKey:  '...',
  privateKey: '...',
}

webpush.setVapidDetails(
  'mailto:...',
  vapidKeys.publicKey,
  vapidKeys.privateKey
)

sendTestPush(user) {
  webpush.sendNotification(user.subscription,
  `Test Push Here!\nJust a test push!`)
  .then(console.log)
  .catch(console.error)
}

Output: (both Mobile and Desktop are similar)

{ statusCode: 201,
  body: '',
  headers:
   { location:
      'https://fcm.googleapis.com/0:15...',
     'x-content-type-options': 'nosniff',
     'x-frame-options': 'SAMEORIGIN',
     'x-xss-protection': '0',
     date: 'Tue, 10 Sep 2019 18:13:39 GMT',
     'content-length': '0',
     'content-type': 'text/html; charset=UTF-8',
     'alt-svc': 'quic=":443"; ma=2592000; v="46,43,39"',
     connection: 'close' } }

service-worker.js:

self.addEventListener("push", function(event) {
  const data = event.data ? event.data.text().split('\n') : ["Title", "Body"]
  const options = {
    body: data[1]
  }
  const promiseChain = self.registration.showNotification(data[0], options)
  event.waitUntil(promiseChain)
})

On Desktop I get:

Test Push Here!
  Just a test push!

On Mobile I get:

Title
  Body

which is being set by service-worker.js in case event.data is missing. What's causing data to be missing on the phone's PWA?

来源:https://stackoverflow.com/questions/57894583/missing-push-data-on-androids-pwa-but-not-on-desktop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!