1async function getStringFromIndexedDB() { 2 return new Promise((resolve, reject) => { 3 const request = indexedDB.open("my-db", 1); 4 5 request.onsuccess = function (event) { 6 const db = event.target.result; 7 8 const transaction = db.transaction(["data"], "readonly"); 9 const objectStore = transaction.objectStore("data"); 10 11 const getRequest = objectStore.get("my-string-key"); 12 getRequest.onsuccess = function (event) { 13 const stringValue = event.target.result; 14 resolve(stringValue); 15 }; 16 17 transaction.oncomplete = function () { 18 db.close(); 19 }; 20 }; 21 22 request.onerror = function (event) { 23 reject(event.target.error); // Reject the promise if an error occurs 24 }; 25 }); 26} 27 28self.addEventListener("push", function (event) { 29 const notificationPayload = event.data.json(); 30 // console.log('notif', notificationPayload); 31 // console.log('localData', window.localStorage.getItem('hello')); 32 33 trackPushNotificationSuccess(notificationPayload.data.title, "received"); 34 35 const notificationTitle = { 36 title: notificationPayload.data.title, 37 }; 38 39 const options = { 40 body: notificationPayload.data.body, 41 image: notificationPayload.data.imageUrl || undefined, 42 data: { 43 url: notificationPayload.data.clickAction || undefined, 44 contentId: notificationPayload.data.contentId || undefined, 45 contentType: notificationPayload.data.contentType || undefined, 46 imageLongUrl: notificationPayload.data.imageLongUrl || undefined, 47 }, 48 }; 49 // console.log('push option', options); 50 51 event.waitUntil( 52 self.registration.showNotification(notificationTitle.title, options) 53 ); 54}); 55 56self.addEventListener("notificationclick", function (event) { 57 trackPushNotificationSuccess(event.notification.title, "opened"); 58 59 event.notification.close(); 60 61 const url = event.notification.data.url; 62 const contentId = event.notification.data.contentId; 63 const contentType = event.notification.data.contentType; 64 const newContentType = contentType === "tv" ? "tv_channel" : contentType; 65 66 if (contentId && newContentType) { 67 clients.openWindow( 68 `https://binge.buzz/playing-${newContentType}/${contentId}` 69 ); 70 // window.open(`https://pre.binge.buzz/playing-${newContentType}/${contentId}`, '_blank'); 71 } 72}); 73 74async function trackPushNotificationSuccess(pushId, status) { 75 try { 76 const stringFromIndexedDB = await getStringFromIndexedDB(); 77 fetch("https://web-api.binge.buzz/api/v3/pushAnalytics", { 78 method: "POST", 79 headers: { 80 "Authorization": `Bearer ${stringFromIndexedDB}`, 81 "os-type": "web", 82 "device-type": "web", 83 }, 84 body: JSON.stringify({ 85 event_type: status, 86 push_id: pushId, 87 }), 88 }) 89 .then((response) => { 90 if (!response) { 91 throw new Error("Failed to track push notification success"); 92 } 93 }) 94 .catch((error) => { 95 console.error("Error tracking push notification success:", error); 96 }); 97 } catch (error) { 98 console.error("Error retrieving string:", error); 99 } 100}
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.