问题
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