From 5381c34ba14cc7b5073451a6d9809b3ec1e71977 Mon Sep 17 00:00:00 2001 From: dwyfrequency Date: Tue, 14 Feb 2023 20:15:57 -0500 Subject: [PATCH 1/4] Update gstatic url for v8 example --- messaging/service-worker.js | 38 ++++++++++++++++++++----------------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/messaging/service-worker.js b/messaging/service-worker.js index 26f9d097..d7520890 100644 --- a/messaging/service-worker.js +++ b/messaging/service-worker.js @@ -10,21 +10,23 @@ function initInSw() { // Give the service worker access to Firebase Messaging. // Note that you can only use Firebase Messaging here. Other Firebase libraries // are not available in the service worker. - importScripts('https://www.gstatic.com/firebasejs/9.2.0/firebase-app.js'); - importScripts('https://www.gstatic.com/firebasejs/9.2.0/firebase-messaging.js'); + importScripts("https://www.gstatic.com/firebasejs/8.10.1/firebase-app.js"); + importScripts( + "https://www.gstatic.com/firebasejs/8.10.1/firebase-messaging.js" + ); // Initialize the Firebase app in the service worker by passing in // your app's Firebase config object. // https://firebase.google.com/docs/web/setup#config-object firebase.initializeApp({ - apiKey: 'api-key', - authDomain: 'project-id.firebaseapp.com', - databaseURL: 'https://project-id.firebaseio.com', - projectId: 'project-id', - storageBucket: 'project-id.appspot.com', - messagingSenderId: 'sender-id', - appId: 'app-id', - measurementId: 'G-measurement-id', + apiKey: "api-key", + authDomain: "project-id.firebaseapp.com", + databaseURL: "https://project-id.firebaseio.com", + projectId: "project-id", + storageBucket: "project-id.appspot.com", + messagingSenderId: "sender-id", + appId: "app-id", + measurementId: "G-measurement-id", }); // Retrieve an instance of Firebase Messaging so that it can handle background @@ -38,16 +40,18 @@ function onBackgroundMessage() { // [START messaging_on_background_message] messaging.onBackgroundMessage((payload) => { - console.log('[firebase-messaging-sw.js] Received background message ', payload); + console.log( + "[firebase-messaging-sw.js] Received background message ", + payload + ); // Customize notification here - const notificationTitle = 'Background Message Title'; + const notificationTitle = "Background Message Title"; const notificationOptions = { - body: 'Background Message body.', - icon: '/firebase-logo.png' + body: "Background Message body.", + icon: "/firebase-logo.png", }; - - self.registration.showNotification(notificationTitle, - notificationOptions); + + self.registration.showNotification(notificationTitle, notificationOptions); }); // [END messaging_on_background_message] } From c230022141088e880ac670f398e5c9034b92edc7 Mon Sep 17 00:00:00 2001 From: dwyfrequency Date: Wed, 15 Feb 2023 12:28:24 -0500 Subject: [PATCH 2/4] Switch to single quotes --- messaging/service-worker.js | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/messaging/service-worker.js b/messaging/service-worker.js index d7520890..00aaf0d4 100644 --- a/messaging/service-worker.js +++ b/messaging/service-worker.js @@ -1,5 +1,5 @@ -import firebase from "firebase/app"; -import "firebase/messaging"; +import firebase from 'firebase/app'; +import 'firebase/messaging'; // See: https://github.com/microsoft/TypeScript/issues/14877 /** @type {ServiceWorkerGlobalScope} */ @@ -10,23 +10,23 @@ function initInSw() { // Give the service worker access to Firebase Messaging. // Note that you can only use Firebase Messaging here. Other Firebase libraries // are not available in the service worker. - importScripts("https://www.gstatic.com/firebasejs/8.10.1/firebase-app.js"); + importScripts('https://www.gstatic.com/firebasejs/8.10.1/firebase-app.js'); importScripts( - "https://www.gstatic.com/firebasejs/8.10.1/firebase-messaging.js" + 'https://www.gstatic.com/firebasejs/8.10.1/firebase-messaging.js' ); // Initialize the Firebase app in the service worker by passing in // your app's Firebase config object. // https://firebase.google.com/docs/web/setup#config-object firebase.initializeApp({ - apiKey: "api-key", - authDomain: "project-id.firebaseapp.com", - databaseURL: "https://project-id.firebaseio.com", - projectId: "project-id", - storageBucket: "project-id.appspot.com", - messagingSenderId: "sender-id", - appId: "app-id", - measurementId: "G-measurement-id", + apiKey: 'api-key', + authDomain: 'project-id.firebaseapp.com', + databaseURL: 'https://project-id.firebaseio.com', + projectId: 'project-id', + storageBucket: 'project-id.appspot.com', + messagingSenderId: 'sender-id', + appId: 'app-id', + measurementId: 'G-measurement-id', }); // Retrieve an instance of Firebase Messaging so that it can handle background @@ -41,14 +41,14 @@ function onBackgroundMessage() { // [START messaging_on_background_message] messaging.onBackgroundMessage((payload) => { console.log( - "[firebase-messaging-sw.js] Received background message ", + '[firebase-messaging-sw.js] Received background message ', payload ); // Customize notification here - const notificationTitle = "Background Message Title"; + const notificationTitle = 'Background Message Title'; const notificationOptions = { - body: "Background Message body.", - icon: "/firebase-logo.png", + body: 'Background Message body.', + icon: '/firebase-logo.png', }; self.registration.showNotification(notificationTitle, notificationOptions); From 8270b5f010d4a4e75f8fdd3b58a8a12dbadbace5 Mon Sep 17 00:00:00 2001 From: dwyfrequency Date: Wed, 15 Feb 2023 13:25:49 -0500 Subject: [PATCH 3/4] Update messaging/service-worker.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove trailing comma Co-authored-by: Rosário Pereira Fernandes --- messaging/service-worker.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/messaging/service-worker.js b/messaging/service-worker.js index 00aaf0d4..5f1c7fff 100644 --- a/messaging/service-worker.js +++ b/messaging/service-worker.js @@ -48,7 +48,7 @@ function onBackgroundMessage() { const notificationTitle = 'Background Message Title'; const notificationOptions = { body: 'Background Message body.', - icon: '/firebase-logo.png', + icon: '/firebase-logo.png' }; self.registration.showNotification(notificationTitle, notificationOptions); From 12affbeaeae1c37cdadeff71e3e2f006080384c2 Mon Sep 17 00:00:00 2001 From: dwyfrequency Date: Wed, 15 Feb 2023 13:26:21 -0500 Subject: [PATCH 4/4] Update messaging/service-worker.js MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Revert to original line formatting for import script Co-authored-by: Rosário Pereira Fernandes --- messaging/service-worker.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/messaging/service-worker.js b/messaging/service-worker.js index 5f1c7fff..c0f875bb 100644 --- a/messaging/service-worker.js +++ b/messaging/service-worker.js @@ -11,9 +11,7 @@ function initInSw() { // Note that you can only use Firebase Messaging here. Other Firebase libraries // are not available in the service worker. importScripts('https://www.gstatic.com/firebasejs/8.10.1/firebase-app.js'); - importScripts( - 'https://www.gstatic.com/firebasejs/8.10.1/firebase-messaging.js' - ); + importScripts('https://www.gstatic.com/firebasejs/8.10.1/firebase-messaging.js'); // Initialize the Firebase app in the service worker by passing in // your app's Firebase config object.