PageSourceSearch

https://www.purina.co.il/modules/custom/nppe_service_worker/js/register-sw.js

js purina.co.il collected 2026-10-02 20:57:01 UTC 1,879 bytes, 58 lines download raw bytes

1(function (Drupal, drupalSettings) {
2  const swEnabled = drupalSettings.nppe_service_worker?.enabled ?? true;
3
4  if ('serviceWorker' in navigator) {
5    if (swEnabled) {
6      // Register Service Worker if enabled.
7      window.addEventListener('load', function () {
8        navigator.serviceWorker.register('/sw.js').then(function (registration) {
9          console.log('ServiceWorker registration successful with scope: ', registration.scope);
10        }, function (err) {
11          console.log('ServiceWorker registration failed: ', err);
12        });
13      });
14    } else {
15      // Disable all active Service Workers if disabled.
16      disableServiceWorkers();
17    }
18  }
19
20  /**
21   * Disables all active Service Workers by unregistering them,
22   * blocking new registrations, and clearing all caches.
23   */
24  function disableServiceWorkers() {
25    // Unregister all active Service Workers.
26    navigator.serviceWorker.getRegistrations()
27      .then((registrations) => {
28        registrations.forEach((registration) => {
29          registration.unregister().then(() => {
30            console.log('Service Worker unregistered:', registration.scope);
31          });
32        });
33      })
34      .catch((err) => {
35        console.error('Error during Service Worker unregistration:', err);
36      });
37
38    // Block new Service Worker registrations.
39    navigator.serviceWorker.register = function () {
40      console.warn('Service Worker registration blocked');
41      return Promise.resolve({
42        unregister: () => Promise.resolve(),
43        active: null,
44        installing: null,
45        waiting: null,
46        scope: '/',
47      });
48    };
49
50    // Clear all caches.
51    if ('caches' in window) {
52      caches.keys()
53        .then((cacheNames) => {
54          return Promise.all(cacheNames.map((cacheName) => caches.delete(cacheName)));
55        })
56    }
57  }
58})(Drupal, drupalSettings);

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.