PageSourceSearch

https://lab7-news.udn.com/static/js/firebase-messaging-sw.js

js udn.com collected 2026-10-01 07:52:58 UTC 2,630 bytes, 79 lines download raw bytes

1// UDN HEALTH
2// [START initialize_firebase_in_sw]
3// Give the service worker access to Firebase Messaging.
4// Note that you can only use Firebase Messaging here, other Firebase libraries
5// are not available in the service worker.
6importScripts('https://www.gstatic.com/firebasejs/10.13.1/firebase-app-compat.js');
7importScripts('https://www.gstatic.com/firebasejs/10.13.1/firebase-messaging-compat.js');
8
9firebase.initializeApp({
10	apiKey: "AIzaSyAqYiyOiGAsFZEkI9Zivu0zmsVKtSJBIrQ",
11	authDomain: "udn-news-bb56c.firebaseapp.com",
12	databaseURL: "https://udn-news-bb56c.firebaseio.com",
13	projectId: "udn-news-bb56c",
14	storageBucket: "udn-news-bb56c.firebasestorage.app",
15	messagingSenderId: "458601607738",
16	appId: "1:458601607738:web:17f5fb38a26f0d31f77b03"
17});
18
19
20// Retrieve an instance of Firebase Messaging so that it can handle background
21// messages.
22const messaging = firebase.messaging();
23// [END initialize_firebase_in_sw]
24
25self.addEventListener('notificationclick', function(event) {
26	console.log('[firebase] Received notificationclick event ', event);		
27	var click_action = event.notification.data;
28	event.notification.close();
29	// This looks to see if the current is already open and
30	// focuses if it is
31	event.waitUntil(clients.matchAll({
32		type: "window"
33	}).then(function(clientList) {
34		for (var i = 0; i < clientList.length; i++) {
35			var client = clientList[i];
36			if (client.url == click_action  && 'focus' in client)
37				return client.focus();
38		}
39		if (clients.openWindow)
40			return clients.openWindow(click_action);
41		}));
42		
43});
44
45const showMessage = function(payload){
46	console.log('[firebase] showMessage', payload);
47	const notificationTitle = payload.data.title;
48	const notificationOptions = {
49		body: payload.data.body,
50		icon: payload.data.icon,
51		image: payload.data.image,
52		click_action: payload.data.click_action,
53		data:payload.data.click_action
54	};	
55 
56  return self.registration.showNotification(notificationTitle,notificationOptions);	
57}	
58
59
60
61// If you would like to customize notifications that are received in the
62// background (Web app is closed or not in browser focus) then you should
63// implement this optional method.
64// [START background_handler]
65messaging.onBackgroundMessage((payload) => {
66    console.log("[firebase] onBackgroundMessage");
67    showMessage(payload);
68});
69  
70/*
71self.addEventListener('message', function (evt) {
72  console.log('[firebase] postMessage received', evt.data);
73  //console.log( 'test', typeof showMessage );
74  console.log("[firebase] self",self);
75  showMessage( evt.data );
76})
77*/
78
79

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.