1importScripts('https://www.gstatic.com/firebasejs/5.8.6/firebase-app.js'); 2importScripts('https://www.gstatic.com/firebasejs/5.8.6/firebase-messaging.js'); 3 4// Set the event listener first to prevent Firefox bug with FCM 5// which crash the notificationclick handler. 6// 7// Ref: https://stackoverflow.com/questions/53595019/service-worker-notificationclick-event-doesnt-focus-or-open-my-website-in-tab 8 9self.addEventListener('notificationclick', function(event) { 10 event.notification.close(); 11 12 var data = { 13 clientId: event.notification.data.clientId, 14 contentId: event.notification.data.contentId, 15 clickUrl: event.notification.data.clickUrl 16 }; 17 var keyValuePairs = []; 18 for (var name in data) { 19 if (!data.hasOwnProperty(name)) continue; 20 if (typeof data[name] === 'function') continue; 21 var value = data[name].toString(); 22 name = encodeURIComponent(name.replace(' ', '+')); 23 value = encodeURIComponent(value.replace(' ', '+')); 24 keyValuePairs.push(name + '=' + value); 25 } 26 var encodedData = keyValuePairs.join('&'); 27 28 var header = new Headers(); 29 header.append('Content-Type', 'application/x-www-form-urlencoded') 30 var init = { 31 method: 'post', 32 headers: header, 33 body: encodedData 34 } 35 36 var request = new Request('/ajax/ctjob/listing/logger.asp', init); 37 38 event.waitUntil(clients.openWindow(event.notification.data.clickUrl).then(async function(windowClient) { 39 var response = await fetch(request); 40 41 if (!response.ok) { 42 var responseText = await response.text(); 43 // console.log('Action log error. ' + responseText); 44 } 45 })); 46}); 47 48var config = { 49 apiKey: "AIzaSyDJuuzEjOzBBo-hR_LEsL2YAswL6biw-lQ", 50 authDomain: "api-project-763980943412.firebaseapp.com", 51 databaseURL: "https://api-project-763980943412.firebaseio.com", 52 projectId: "api-project-763980943412", 53 storageBucket: "api-project-763980943412.appspot.com", 54 messagingSenderId: "763980943412" 55}; 56 57firebase.initializeApp(config); 58var messaging = firebase.messaging(); 59 60messaging.setBackgroundMessageHandler(function(payload) { 61 // console.log('[firebase-messaging-sw.js] Received background message.'); 62 63 var title = payload.data.title; 64 var options = { 65 body: payload.data.messageBody, 66 icon: '/images/web-notification-icon.png', 67 tag: payload.data.tag, 68 actions: [], 69 data: { 70 clickUrl: payload.data.url, 71 contentId: payload.data.content_id, 72 clientId: payload.data.client_id 73 } 74 }; 75 76 return self.registration.showNotification(title, options); 77});
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.