1 var OFFLINE_PAGE_URL = '/offline.pwa.html'; 2 3 self.addEventListener('install', function (event) { 4 console.log('********** The service worker is being installed.'); 5 6 // Store "Offline" page 7 var offlineRequest = new Request(OFFLINE_PAGE_URL, {init: { 8 credentials: 'omit' 9 }}); 10 11 event.waitUntil( 12 fetch(offlineRequest).then(function (response) { 13 return caches.open('offline').then(function (cache) { 14 console.log('[oninstall] Cached offline page', response.url); 15 return cache.put(offlineRequest, response); 16 }); 17 }) 18 ); 19 }); 20/** 21 * Service worker addon for FCM push notifications, appended to the PWA service 22 * worker by ServiceWorkerService before the Firebase importScripts, so the 23 * notificationclick handler below is called before Firebase's own handler. 24 */ 25 26// Activate updated service workers immediately instead of waiting for all 27// app windows to close - iOS PWAs may otherwise keep an old SW for a long time. 28self.addEventListener('install', function () { 29 self.skipWaiting(); 30}); 31self.addEventListener('activate', function (event) { 32 event.waitUntil(self.clients.claim()); 33}); 34 35// Handle notification clicks ourselves, before Firebase's own handler, which 36// only focuses an already-open window without navigating it (it delegates 37// navigation to a postMessage the page never listens for). 38// 39// Known limitation (iOS/WebKit bug, iOS 17/18): when the PWA is already 40// running, iOS never dispatches notificationclick at all, so tapping a 41// notification only brings the app to the foreground without navigating. 42// This is intentionally not worked around here - no service-worker code can 43// ever see that tap. See https://github.com/humhub/fcm-push/pull/99 for an 44// exploration of a page-side heuristic covering that case. 45self.addEventListener('notificationclick', function (event) { 46 const fcmMsg = event.notification && event.notification.data && event.notification.data.FCM_MSG; 47 const url = fcmMsg && ((fcmMsg.fcmOptions && fcmMsg.fcmOptions.link) || (fcmMsg.data && fcmMsg.data.url)); 48 if (!url) { 49 return; // Not one of our notifications - leave it to Firebase's handler 50 } 51 52 // Take over completely: prevent Firebase's handler from running. 53 event.stopImmediatePropagation(); 54 event.notification.close(); 55 56 event.waitUntil( 57 self.clients.matchAll({type: 'window', includeUncontrolled: true}).then(function (clientList) { 58 // matchAll() returns window clients most-recently-focused first. 59 const client = clientList.find(function (c) { return 'navigate' in c; }); 60 if (!client) { 61 return self.clients.openWindow(url); 62 } 63 return Promise.resolve(client.focus()) 64 .catch(function () { return client; }) 65 .then(function (c) { return (c || client).navigate(url); }) 66 .catch(function () { return self.clients.openWindow(url); }); 67 }) 68 ); 69}); 70 importScripts('/assets/64d05d11/firebase-app-compat.js'); 71 importScripts('/assets/64d05d11/firebase-messaging-compat.js'); 72 73 firebase.initializeApp({ 74 messagingSenderId: "464374718065", 75 projectId: "humhub-push-notifications", 76 appId: "1:464374718065:web:8470b9d17d4979b7e385d0", 77 apiKey: "AIzaSyAq1NEn9rWyWBVFJ5gJXlShtZbVVzCoG4Q", 78 }); 79 80 // Initialize Firebase Cloud Messaging and get a reference to the service 81 firebase.messaging();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.