我试图让我的“click_action”将用户带到我发送给客户端的通知上的特定 URL,但无论我做什么,它要么不执行任何操作(桌面),要么只是打开 PWA(android)。消息传输正常(在 Chrome 控制台中检查),但点击似乎不起作用。
\n\n我的服务人员中有以下内容,是从各个地方抄来的,包括本网站上提供的其他答案:
\n\nimportScripts(\'https://www.gstatic.com/firebasejs/7.14.3/firebase-app.js\');\nimportScripts(\'https://www.gstatic.com/firebasejs/7.14.3/firebase-messaging.js\');\n// importScripts(\'/__/firebase/init.js\');\n\n/* An empty service worker! */\nself.addEventListener(\'fetch\', function(event) {\n /* An empty fetch handler! */\n});\n\n var firebaseConfig = {\n//REDACTED\n };\n // Initialize Firebase\n firebase.initializeApp(firebaseConfig);\n\n const messaging = firebase.messaging();\n\nmessaging.setBackgroundMessageHandler(function(payload) {\n console.log(\'[firebase-messaging-sw.js] Received background message \', payload);\n // Customize notification here\n\n\n notificationTitle = payload.notification.title;\n notificationOptions = {\n body: payload.notification.body,\n icon: payload.notification.icon,\n click_action: payload.notification.click_action\n };\n\n return self.registration.showNotification(notificationTitle,\n notificationOptions);\n});\n\nself.addEventListener(\'notificationclick\', function(event) {\n let url = event.notification.click_action;\n// I\'ve also added a data.click_action field in my JSON notification, and …
Run Code Online (Sandbox Code Playgroud)