0
我试图制作云消息服务器,它将通知发送给Chrome(PC和移动设备)。 我发现https://developers.google.com/web/fundamentals/getting-started/codelabs/push-notifications/和教程的作品。Chrome消息传递 - 显示数据而不是固定消息
在本教程中有一个听众:
self.addEventListener('push', function(event) {
console.log('[Service Worker] Push Received.');
console.log(`[Service Worker] Push had this data: "${event.data.text()}"`);
const title = 'Push Codelap';
const options = {
body: 'Yay it works.',
icon: 'images/icon.png',
badge: 'images/badge.png'
};
event.waitUntil(self.registration.showNotification(title, options));
});
和它的作品 - 当我通过https://web-push-codelab.appspot.com/它似乎发送“世界,你好” ......但只有在执行console.log。
如何更改选项以获得${event.data.text()}
intead的Yay it works
?
我试图改变body: 'Yay it works.',
到body: ${event.data.text()},
但Syntax Error: Unexpected token {
出现。
您需要使用字符串模板'$ {event.data.text()}' – Hosar
@Hosar这会导致语法错误:意外的标记{ –