PageSourceSearch

https://www.labaroviola.com/service-worker.js

js labaroviola.com collected 2026-10-02 19:32:59 UTC 2,834 bytes, 81 lines download raw bytes

1const TRACKING_ENDPOINT = 'https://push.webmaster360.it/api/track';
2var CACHE_DYNAMIC_NAME = 'dynamic-v1';
3
4self.addEventListener('install', event => {
5    console.log('[Webmaster360 Service Worker] Installing Service Worker ...', event);
6    self.skipWaiting();
7});
8
9self.addEventListener('activate', event => {
10    console.log('[Webmaster360 Service Worker] Activating Service Worker ...', event);
11    return self.clients.claim();
12});
13
14/*
15self.addEventListener('fetch', event => {
16    event.respondWith(fetch(event.request));
17});
18*/
19
20self.addEventListener('push', event => {
21    console.log('[Webmaster360 Service Worker] Push event received.');
22
23    let data = {};
24    if (event.data) {
25        try {
26            data = event.data.json();
27        } catch (e) {
28            console.error('[Webmaster360 Service Worker] Error parsing push data', e);
29            return;
30        }
31    }
32
33    // Verify that mandatory fields are present: title, body, icon, url, and push_id
34    if (!data.title || !data.body || !data.icon || !data.url || !data.push_id) {
35        console.error('[Webmaster360 Service Worker] Incomplete data for notification. Notification cancelled.');
36        return;
37    }
38
39    // Build the URL for tracking the "view" event using new parameter names
40    const siteName = self.location.host.replace(/^www\./, '');
41    const viewTrackingUrl = `${TRACKING_ENDPOINT}?domain=${siteName}&push_id=${data.push_id}&action=view`;
42
43    // Execute tracking of the view event
44    fetch(viewTrackingUrl, { method: 'GET' })
45        .then(response => response.json())
46        .catch(err => console.error('[Webmaster360 Service Worker] Error tracking view event', err));
47
48    const title = data.title;
49    const options = {
50        body: data.body,
51        icon: data.icon,
52        requireInteraction: true,
53        data: {
54            url: data.url,
55            push_id: data.push_id
56        }
57    };
58
59    event.waitUntil(
60        self.registration.showNotification(title, options)
61    );
62});
63
64self.addEventListener('notificationclick', event => {
65    console.log('[Webmaster360 Service Worker] Notification click received', event.notification);
66    event.notification.close();
67
68    // Build the URL for tracking the "click" event using the new parameter names
69    const siteName = self.location.host.replace(/^www\./, '');
70    const clickTrackingUrl = `${TRACKING_ENDPOINT}?domain=${siteName}&push_id=${event.notification.data.push_id}&action=click`;
71
72    // Execute tracking of the click event
73    fetch(clickTrackingUrl, { method: 'GET' })
74        .then(response => response.json())
75        .catch(err => console.error('[Webmaster360 Service Worker] Error tracking click event', err));
76
77    // Always open a new window with the specified URL
78    event.waitUntil(
79        clients.openWindow(event.notification.data.url)
80    );
81});

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.