How to use workbox-window - 10 common examples

To help you get started, we’ve selected a few workbox-window examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DefinitelyTyped / DefinitelyTyped / types / workbox-window / workbox-window-tests.ts View on Github external
Workbox,
    WorkboxEvent,
    WorkboxEventMap,
    messageSW,
} from "workbox-window";

//==============================================================================
// WorkboxWindow.Workbox
//==============================================================================

export namespace WorkboxTest {
    declare const url: string;
    declare const options: RegistrationOptions;

    // $ExpectType Workbox
    new Workbox(url);
    // $ExpectType Workbox
    new Workbox(url, options);

    declare const workbox: Workbox;
    declare const event: WorkboxEvent;
    declare const eventListener: () => void;
    declare const eventType: keyof WorkboxEventMap;
    declare const messageData: any;
    declare const registerOptions: Workbox.RegisterOptions;

    // $ExpectType Promise
    workbox.active;

    // $ExpectType Promise
    workbox.controlling;
github DefinitelyTyped / DefinitelyTyped / types / workbox-window / workbox-window-tests.ts View on Github external
WorkboxEventMap,
    messageSW,
} from "workbox-window";

//==============================================================================
// WorkboxWindow.Workbox
//==============================================================================

export namespace WorkboxTest {
    declare const url: string;
    declare const options: RegistrationOptions;

    // $ExpectType Workbox
    new Workbox(url);
    // $ExpectType Workbox
    new Workbox(url, options);

    declare const workbox: Workbox;
    declare const event: WorkboxEvent;
    declare const eventListener: () => void;
    declare const eventType: keyof WorkboxEventMap;
    declare const messageData: any;
    declare const registerOptions: Workbox.RegisterOptions;

    // $ExpectType Promise
    workbox.active;

    // $ExpectType Promise
    workbox.controlling;

    // $ExpectType void
    workbox.addEventListener(eventType, eventListener);
github DefinitelyTyped / DefinitelyTyped / types / workbox-window / workbox-window-tests.ts View on Github external
workbox.register(registerOptions);

    // $ExpectType void
    workbox.removeEventListener(eventType, eventListener);
}

//==============================================================================
// WorkboxWindow.messageSW
//==============================================================================

export namespace MessageSWTest {
    declare const data: any;
    declare const worker: ServiceWorker;

    // $ExpectType Promise
    messageSW(worker, data);
}
github v4lli / meteocool / frontend / src / index.js View on Github external
}

window.injectSettings = (newSettings) => {
  for (var key in newSettings) {
    settings.set(key, newSettings[key]);
  }
};

if (toggleButton) {
  toggleButton.onclick = () => settings.set("darkMode", !settings.get("darkMode"));
  ;
}

// Register service worker
if ("serviceWorker" in navigator) {
  const wb = new Workbox("sw.js");
  wb.addEventListener("waiting", (event) => {
    wb.addEventListener("controlling", (event) => {
      console.log("Reloading page for latest content");
      window.location.reload();
    });
    wb.messageSW({ type: "SKIP_WAITING" });
    // Old serviceworker message for migration, can be removed in the future
    wb.messageSW("SKIP_WAITING");
  });
  wb.register();
}

// purge old lightning strikes on restart
setTimeout(() => { strikemgr.fadeStrikes(); }, 30 * 1000);

/* vim: set ts=2 sw=2 expandtab: */
github Flowm / satvis / src / app.js View on Github external
cc.sats.addFromTleUrl("data/tle/norad/starlink.txt", ["Starlink"]);
cc.sats.addFromTleUrl("data/tle/norad/globalstar.txt", ["Globalstar"]);
cc.sats.addFromTleUrl("data/tle/norad/resource.txt", ["Resource"]);
cc.sats.addFromTleUrl("data/tle/norad/science.txt", ["Science"]);
cc.sats.addFromTleUrl("data/tle/norad/stations.txt", ["Stations"]);
cc.sats.addFromTleUrl("data/tle/norad/weather.txt", ["Weather"]);
cc.sats.addFromTleUrl("data/tle/norad/tle-new.txt", ["New"]);

cc.sats.addFromTleUrl("data/tle/ext/move.txt", ["MOVE"]);
if (cc.sats.enabledTags.length === 0) {
  cc.sats.enableTag("MOVE");
}

// Register service worker
if ("serviceWorker" in navigator) {
  const wb = new Workbox("sw.js");
  wb.addEventListener("waiting", () => {
    wb.addEventListener("controlling", () => {
      console.log("Reloading page for latest content");
      window.location.reload();
    });
    wb.messageSW({type: "SKIP_WAITING"});
    // Old serviceworker message for migration, can be removed in the future
    wb.messageSW("SKIP_WAITING");
  });
  wb.register();
}
github sebastienbarbier / seven23_webapp / src / app / main.js View on Github external
useEffect(() => {
    // Connect with workbow to display snackbar when update is available.
    if (process.env.NODE_ENV != "development" && "serviceWorker" in navigator) {
      const wb = new Workbox("/service-worker.js");
      wb.addEventListener("waiting", event => {
        wb.addEventListener("controlling", event => {
          AppActions.reload();
        });

        dispatch(
          AppActions.cacheDidUpdate(() => {
            wb.messageSW({ type: "SKIP_WAITING" });
          })
        );
      });
      wb.register();
    }
  }, []);
github justinribeiro / blog-pwa / app / src / blog-pwa.js View on Github external
import('./lazy-resources.js').then(_ => {
        if ('serviceWorker' in navigator) {
          const wb = new Workbox('/service-worker.js');

          wb.addEventListener('activated', event => {
            if (!event.isUpdate) {
              this._setSnackBarText('Ready to work offline.');
            }

            // Get the current page URL + all resources the page loaded.
            const urlsToCache = [
              location.href,
              ...performance.getEntriesByType('resource').map(r => r.name),
            ];
            // Send that list of URLs to your router in the service worker.
            wb.messageSW({
              type: 'CACHE_URLS',
              payload: {urlsToCache},
            });
github padloc / padloc / packages / app / src / mixins / service-worker.ts View on Github external
initSW() {
            if (!("serviceWorker" in navigator)) {
                return;
            }

            this._wb = new Workbox("/sw.js");

            // Add an event listener to detect when the registered
            // service worker has installed but is waiting to activate.
            this._wb.addEventListener("waiting", () => {
                setTimeout(() => {
                    this._updateReady();
                }, 1000);
            });

            this._wb.register();
        }
github philipwalton / blog / assets / javascript / sw-init.js View on Github external
export const init = async () => {
  // Instantiating the Workbox instance adds an event listener to
  // `navigator.serviceWorker`, which will be undefined in older browsers.
  wb = new Workbox('/sw.js');

  addNavigationReportListener();
  addFirstInstalledListener();
  addCacheUpdateListener();
  addSWUpdateListener();

  const {log} = await import('./log');
  log.awaitBeforeSending(setSiteVersionOrTimeout());
  log.awaitBeforeSending(setNavigationCacheOrTimeout());

  // Calling register must happen after all presend dependencies get added.
  await wb.register();
};
github shadowwalker / next-pwa / register.js View on Github external
import { Workbox } from 'workbox-window'

if (typeof window !== 'undefined' && 'serviceWorker' in navigator) {
  const wb = new Workbox(__PWA_SW__, { scope: __PWA_SCOPE__ })

  wb.addEventListener('installed', event => {
    if (!event.isUpdate) {
      console.log('[PWA] service worker installed for first time!')
    } else {
      console.log('[PWA] service worker installed by an update!')
    }
  })
  
  wb.addEventListener('activated', event => {
    if (!event.isUpdate) {
      console.log('[PWA] service worker activated for first time!')
    } else {
      console.log('[PWA] service worker activated by an update!')
    }
  })

workbox-window

Simplifies communications with Workbox packages running in the service worker

MIT
Latest version published 23 days ago

Package Health Score

97 / 100
Full package analysis