PageSourceSearch

https://snich.ai/push-sw.js

js snich.ai collected 2026-10-05 15:08:10 UTC 1,748 bytes, 36 lines download raw bytes

1/* SNICH push notifications. Only push and notification clicks: no fetch handler, no caching —
2   pages never depend on this worker (its scope is /push/, it controls no page). */
3self.addEventListener('install', () => self.skipWaiting());
4self.addEventListener('activate', (event) => event.waitUntil(self.clients.claim()));
5
6self.addEventListener('push', (event) => {
7  let data = {};
8  try {
9    data = event.data ? event.data.json() : {};
10  } catch (e) {
11    data = { body: event.data ? event.data.text() : '' };
12  }
13  const title = data.title || 'SNICH';
14  event.waitUntil(self.registration.showNotification(title, {
15    body: data.body || '',
16    icon: '/brand/snich-mark.png',
17    badge: '/brand/snich-mark.png',
18    tag: data.tag || undefined,
19    renotify: Boolean(data.tag),
20    data: { url: data.url || '/' },
21  }));
22});
23
24self.addEventListener('notificationclick', (event) => {
25  event.notification.close();
26  const target = new URL((event.notification.data && event.notification.data.url) || '/', self.location.origin);
27  // Only our own pages (the app, event pages on events.snich.ai): never another site.
28  const safe = target.origin === self.location.origin || (target.protocol === 'https:' && /(^|\.)snich\.ai$/.test(target.hostname));
29  const url = safe ? target.href : self.location.origin + '/';
30  // This worker controls no page (scope /push/), so it cannot navigate an open tab: a tab already
31  // on that page is focused, otherwise the page opens in a new one.
32  event.waitUntil(self.clients.matchAll({ type: 'window', includeUncontrolled: true }).then((windows) => {
33    const open = windows.find((client) => client.url === url && 'focus' in client);
34    return open ? open.focus() : self.clients.openWindow(url);
35  }));
36});

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.