TF-1802 Fix fcm broken on web

(cherry picked from commit a5c88da70482ff9dfad53b2c3582ec860ca237dc)
This commit is contained in:
dab246
2023-05-15 11:20:49 +07:00
committed by Dat Vu
parent 63f375a29c
commit e0244f38c2
2 changed files with 10 additions and 3 deletions
+3 -1
View File
@@ -1,6 +1,6 @@
importScripts("https://www.gstatic.com/firebasejs/9.10.0/firebase-app-compat.js");
importScripts("https://www.gstatic.com/firebasejs/9.10.0/firebase-messaging-compat.js");
// Initialize the Firebase app in the service worker by passing in the messagingSenderId.
firebase.initializeApp({
apiKey: "...",
authDomain: "...",
@@ -10,3 +10,5 @@ firebase.initializeApp({
messagingSenderId: "...",
appId: "...",
});
// Retrieve an instance of Firebase Messaging so that it can handle background messages.
const messaging = firebase.messaging();
+6 -1
View File
@@ -58,7 +58,12 @@
// Wait for registration to finish before dropping the <script> tag.
// Otherwise, the browser will load the script multiple times,
// potentially different versions.
navigator.serviceWorker.register('firebase-messaging-sw.js');
navigator.serviceWorker.register('firebase-messaging-sw.js').then(serviceWorkerRegistration => {
console.info('Service worker firebase-messaging was registered.');
}).catch(error => {
console.error('An error occurred while registering the service worker firebase-messaging.');
console.error(error);
});
var serviceWorkerUrl = 'flutter_service_worker.js?v=' + serviceWorkerVersion;
navigator.serviceWorker.register(serviceWorkerUrl)
.then((reg) => {