1self.addEventListener('notificationclick', function(event) { 2 event.stopImmediatePropagation(); 3 event.notification.close(); 4 event.waitUntil( 5 self.clients.openWindow(event.notification.data.url) 6 ); 7} 8, false); 9 10// [START initialize_firebase_in_sw] 11// Give the service worker access to Firebase Messaging. 12// Note that you can only use Firebase Messaging here, other Firebase libraries 13// are not available in the service worker. 14importScripts('https://www.gstatic.com/firebasejs/5.9.1/firebase-app.js'); 15importScripts('https://www.gstatic.com/firebasejs/5.9.1/firebase-messaging.js'); 16 17// Initialize the Firebase app in the service worker by passing in the 18// messagingSenderId. 19firebase.initializeApp({ 20 'messagingSenderId': '438883655217' 21}); 22 23// Retrieve an instance of Firebase Messaging so that it can handle background 24// messages. 25const messaging = firebase.messaging(); 26// [END initialize_firebase_in_sw] 27 28if (firebase.messaging.isSupported()) { 29 // If you would like to customize notifications that are received in the 30 // background (Web app is closed or not in browser focus) then you should 31 // implement this optional method. 32 // [START background_handler] 33 messaging.setBackgroundMessageHandler(function(payload) { 34 console.log('[firebase-messaging-sw.js] Received background message ', payload); 35 // Customize notification here 36 var notificationTitle = payload.data.title; 37 var notificationOptions = { 38 body: payload.data.body, 39 icon: payload.data.icon, 40 requireInteraction: true, 41 data: { url:payload.data.click_action }, 42 }; 43 44 return self.registration.showNotification(notificationTitle, notificationOptions); 45 }); 46 // [END background_handler] 47}
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.