├── .gitattributes ├── .github ├── ISSUE_TEMPLATE.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── pull-request.yml │ └── scorecards-analysis.yml ├── .gitignore ├── .husky ├── .gitignore ├── pre-commit └── pre-push ├── .ncurc.js ├── .nvmrc ├── .prettierignore ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── cdn-details.json ├── demos ├── README.md └── src │ ├── workbox-background-sync-demo │ ├── index.html │ ├── package.json │ ├── public │ │ └── example.txt │ ├── sw.js │ └── updateServer.js │ ├── workbox-broadcast-update-demo │ ├── index.html │ ├── package.json │ ├── sw.js │ └── updateServer.js │ ├── workbox-cacheable-response │ ├── index.html │ ├── package.json │ ├── server.js │ └── sw.js │ ├── workbox-core │ ├── index.html │ ├── package.json │ ├── sw.js │ └── updateServer.js │ ├── workbox-expiration │ ├── index.html │ ├── package.json │ ├── sw.js │ └── updateServer.js │ ├── workbox-google-analytics │ ├── index.html │ ├── package.json │ ├── sw.js │ └── updateServer.js │ ├── workbox-navigation-preload │ ├── index.html │ ├── package.json │ ├── sw.js │ └── updateServer.js │ ├── workbox-precaching │ ├── index.html │ ├── package.json │ ├── public │ │ ├── hello-world.1234.txt │ │ ├── hello-world.5678.txt │ │ └── test-file.txt │ ├── sw-1.js │ ├── sw-2.js │ └── updateServer.js │ ├── workbox-range-requests │ ├── index.html │ ├── package.json │ ├── sw.js │ └── updateServer.js │ ├── workbox-routing │ ├── index.html │ ├── package.json │ ├── public │ │ ├── demo-img.png │ │ └── demo-popper.png │ ├── sw.js │ └── updateServer.js │ ├── workbox-strategies │ ├── index.html │ ├── public │ │ ├── cache-first.txt │ │ ├── network-first.txt │ │ ├── network-only.txt │ │ └── stale-while-revalidate.txt │ ├── sw.js │ └── updateServer.js │ ├── workbox-streams │ ├── index.html │ ├── package.json │ ├── server.js │ └── sw.js │ ├── workbox-sw │ ├── README.md │ ├── index.html │ ├── package.json │ ├── public │ │ └── demo-img.png │ ├── sw.js │ └── updateServer.js │ └── workbox-window │ ├── index.html │ ├── package.json │ ├── sw.js │ └── updateServer.js ├── gulp-tasks ├── analyze-properties.js ├── build-node-packages.js ├── build-packages.js ├── build-sw-packages.js ├── build-window-packages.js ├── build.js ├── docs.js ├── lint.js ├── publish-cdn.js ├── publish-github.js ├── publish-glitch.js ├── publish-lerna.js ├── publish.js ├── test-integration.js ├── test-node.js ├── test-server.js ├── test.js ├── transpile-typescript.js └── utils │ ├── analyse-properties.js │ ├── cdn-helper.js │ ├── constants.js │ ├── get-packages.js │ ├── github-helper.js │ ├── node-projects-babel.config.json │ ├── output-filename-to-package-map.js │ ├── package-runner.js │ ├── pkg-path-to-name.js │ ├── publish-helpers.js │ ├── rollup-helper.js │ ├── version-module.js │ └── versioned-cdn-url.js ├── gulpfile.js ├── infra ├── pr-bot │ └── aggregate-size-plugin.js ├── templates │ └── reference-docs │ │ └── jsdoc │ │ ├── lang │ │ └── en.yaml │ │ ├── lib │ │ └── publishjob.js │ │ ├── publish.js │ │ ├── static │ │ └── jsdoc.css │ │ └── views │ │ ├── augments.hbs │ │ ├── classes-links.hbs │ │ ├── details-table-row.hbs │ │ ├── details-table.hbs │ │ ├── implements.hbs │ │ ├── index-all.hbs │ │ ├── index.hbs │ │ ├── layout.hbs │ │ ├── params.hbs │ │ ├── properties.hbs │ │ ├── see.hbs │ │ ├── signature.hbs │ │ ├── symbol-content.hbs │ │ ├── symbol-detail.hbs │ │ ├── symbol-header.hbs │ │ ├── symbol-index-section.hbs │ │ ├── symbol-index.hbs │ │ ├── symbol-labels.hbs │ │ ├── symbol-overview.hbs │ │ └── toc-yaml.hbs ├── testing │ ├── activate-and-control.js │ ├── activate-sw-safari.js │ ├── auto-stub-logger.mjs │ ├── clean-sw.js │ ├── comlink │ │ ├── node-interface.js │ │ ├── sw-interface.js │ │ └── window-interface.js │ ├── confirm-directory-contains.js │ ├── env-it.js │ ├── expectError.js │ ├── generate-variant-tests.js │ ├── helpers │ │ ├── compareResponses.mjs │ │ ├── extendable-event-utils.mjs │ │ ├── generateOpaqueResponse.mjs │ │ ├── generateUniqueResponse.mjs │ │ └── sleep.mjs │ ├── server │ │ ├── cross-origin-server.js │ │ ├── index.js │ │ ├── request-counter.js │ │ ├── routes │ │ │ ├── build-file.js │ │ │ ├── comlink.js │ │ │ ├── integration-html.js │ │ │ ├── sw-bundle.js │ │ │ ├── templates-update.js │ │ │ ├── templates.js │ │ │ ├── test-sw.js │ │ │ ├── test-window.js │ │ │ ├── unique-etag.js │ │ │ └── unique-value.js │ │ ├── static │ │ │ └── integration.html │ │ ├── template-data.js │ │ └── templates │ │ │ ├── integration.html.njk │ │ │ ├── sw-clients-claim.js.njk │ │ │ ├── sw-no-skip-waiting.js.njk │ │ │ ├── sw-script-version.js.njk │ │ │ ├── sw-skip-waiting-deferred.js.njk │ │ │ ├── sw-skip-waiting-on-message.js.njk │ │ │ ├── sw-skip-waiting.js.njk │ │ │ ├── sw-window-ready.js.njk │ │ │ ├── test-sw-runner.js.njk │ │ │ ├── test-sw.html.njk │ │ │ └── test-window.html.njk │ ├── validator │ │ └── service-worker-runtime.js │ ├── wait-until.js │ ├── webdriver │ │ ├── IframeManager.js │ │ ├── executeAsyncAndCatch.js │ │ ├── runUnitTests.js │ │ ├── unregisterAllSWs.js │ │ └── windowLoaded.js │ └── webpack-build-check.js ├── type-overrides.d.ts └── utils │ ├── AsyncDebounce.js │ └── log-helper.js ├── javascript.eslintrc.js ├── jsdoc.conf ├── lerna.json ├── package-lock.json ├── package.json ├── packages ├── workbox-background-sync │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── BackgroundSyncPlugin.ts │ │ ├── Queue.ts │ │ ├── QueueStore.ts │ │ ├── StorableRequest.ts │ │ ├── _version.ts │ │ ├── index.ts │ │ └── lib │ │ │ ├── QueueDb.ts │ │ │ ├── QueueStore.ts │ │ │ └── StorableRequest.ts │ └── tsconfig.json ├── workbox-broadcast-update │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── BroadcastCacheUpdate.ts │ │ ├── BroadcastUpdatePlugin.ts │ │ ├── _version.ts │ │ ├── index.ts │ │ ├── responsesAreSame.ts │ │ └── utils │ │ │ └── constants.ts │ └── tsconfig.json ├── workbox-build │ ├── .ncurc.js │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── _types.js │ │ ├── cdn-details.json │ │ ├── generate-sw.ts │ │ ├── get-manifest.ts │ │ ├── index.ts │ │ ├── inject-manifest.ts │ │ ├── lib │ │ │ ├── additional-manifest-entries-transform.ts │ │ │ ├── bundle.ts │ │ │ ├── cdn-utils.ts │ │ │ ├── copy-workbox-libraries.ts │ │ │ ├── errors.ts │ │ │ ├── escape-regexp.ts │ │ │ ├── get-composite-details.ts │ │ │ ├── get-file-details.ts │ │ │ ├── get-file-hash.ts │ │ │ ├── get-file-manifest-entries.ts │ │ │ ├── get-file-size.ts │ │ │ ├── get-source-map-url.ts │ │ │ ├── get-string-details.ts │ │ │ ├── get-string-hash.ts │ │ │ ├── maximum-size-transform.ts │ │ │ ├── modify-url-prefix-transform.ts │ │ │ ├── module-registry.ts │ │ │ ├── no-revision-for-urls-matching-transform.ts │ │ │ ├── populate-sw-template.ts │ │ │ ├── rebase-path.ts │ │ │ ├── replace-and-update-source-map.ts │ │ │ ├── runtime-caching-converter.ts │ │ │ ├── stringify-without-comments.ts │ │ │ ├── transform-manifest.ts │ │ │ ├── translate-url-to-sourcemap-paths.ts │ │ │ ├── validate-options.ts │ │ │ └── write-sw-using-default-template.ts │ │ ├── rollup-plugin-off-main-thread.d.ts │ │ ├── schema │ │ │ ├── GenerateSWOptions.json │ │ │ ├── GetManifestOptions.json │ │ │ ├── InjectManifestOptions.json │ │ │ ├── WebpackGenerateSWOptions.json │ │ │ └── WebpackInjectManifestOptions.json │ │ ├── strip-comments.d.ts │ │ ├── templates │ │ │ └── sw-template.ts │ │ └── types.ts │ └── tsconfig.json ├── workbox-cacheable-response │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── CacheableResponse.ts │ │ ├── CacheableResponsePlugin.ts │ │ ├── _version.ts │ │ └── index.ts │ └── tsconfig.json ├── workbox-cli │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── app.ts │ │ ├── bin.ts │ │ └── lib │ │ │ ├── cleanup-stack-trace.ts │ │ │ ├── constants.ts │ │ │ ├── errors.ts │ │ │ ├── help-text.ts │ │ │ ├── logger.ts │ │ │ ├── questions │ │ │ ├── ask-config-location.ts │ │ │ ├── ask-extensions-to-cache.ts │ │ │ ├── ask-questions.ts │ │ │ ├── ask-root-of-web-app.ts │ │ │ ├── ask-start_url-query-params.ts │ │ │ ├── ask-sw-dest.ts │ │ │ └── ask-sw-src.ts │ │ │ ├── read-config.ts │ │ │ └── run-wizard.ts │ └── tsconfig.json ├── workbox-core │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── _private.ts │ │ ├── _private │ │ │ ├── Deferred.ts │ │ │ ├── WorkboxError.ts │ │ │ ├── assert.ts │ │ │ ├── cacheMatchIgnoreParams.ts │ │ │ ├── cacheNames.ts │ │ │ ├── canConstructReadableStream.ts │ │ │ ├── canConstructResponseFromBodyStream.ts │ │ │ ├── dontWaitFor.ts │ │ │ ├── executeQuotaErrorCallbacks.ts │ │ │ ├── getFriendlyURL.ts │ │ │ ├── logger.ts │ │ │ ├── resultingClientExists.ts │ │ │ ├── timeout.ts │ │ │ └── waitUntil.ts │ │ ├── _version.ts │ │ ├── cacheNames.ts │ │ ├── clientsClaim.ts │ │ ├── copyResponse.ts │ │ ├── index.ts │ │ ├── models │ │ │ ├── messages │ │ │ │ ├── messageGenerator.ts │ │ │ │ └── messages.ts │ │ │ ├── pluginEvents.ts │ │ │ └── quotaErrorCallbacks.ts │ │ ├── registerQuotaErrorCallback.ts │ │ ├── setCacheNameDetails.ts │ │ ├── skipWaiting.ts │ │ ├── types.ts │ │ └── utils │ │ │ ├── pluginUtils.ts │ │ │ └── welcome.ts │ └── tsconfig.json ├── workbox-expiration │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── CacheExpiration.ts │ │ ├── ExpirationPlugin.ts │ │ ├── _version.ts │ │ ├── index.ts │ │ └── models │ │ │ └── CacheTimestampsModel.ts │ └── tsconfig.json ├── workbox-google-analytics │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── _version.ts │ │ ├── index.ts │ │ ├── initialize.ts │ │ └── utils │ │ │ └── constants.ts │ └── tsconfig.json ├── workbox-navigation-preload │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── _version.ts │ │ ├── disable.ts │ │ ├── enable.ts │ │ ├── index.ts │ │ └── isSupported.ts │ └── tsconfig.json ├── workbox-precaching │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── PrecacheController.ts │ │ ├── PrecacheFallbackPlugin.ts │ │ ├── PrecacheRoute.ts │ │ ├── PrecacheStrategy.ts │ │ ├── _types.ts │ │ ├── _version.ts │ │ ├── addPlugins.ts │ │ ├── addRoute.ts │ │ ├── cleanupOutdatedCaches.ts │ │ ├── createHandlerBoundToURL.ts │ │ ├── getCacheKeyForURL.ts │ │ ├── index.ts │ │ ├── matchPrecache.ts │ │ ├── precache.ts │ │ ├── precacheAndRoute.ts │ │ └── utils │ │ │ ├── PrecacheCacheKeyPlugin.ts │ │ │ ├── PrecacheInstallReportPlugin.ts │ │ │ ├── createCacheKey.ts │ │ │ ├── deleteOutdatedCaches.ts │ │ │ ├── generateURLVariations.ts │ │ │ ├── getCacheKeyForURL.ts │ │ │ ├── getOrCreatePrecacheController.ts │ │ │ ├── printCleanupDetails.ts │ │ │ ├── printInstallDetails.ts │ │ │ └── removeIgnoredSearchParams.ts │ └── tsconfig.json ├── workbox-range-requests │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── RangeRequestsPlugin.ts │ │ ├── _version.ts │ │ ├── createPartialResponse.ts │ │ ├── index.ts │ │ └── utils │ │ │ ├── calculateEffectiveBoundaries.ts │ │ │ └── parseRangeHeader.ts │ └── tsconfig.json ├── workbox-recipes │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── _version.ts │ │ ├── googleFontsCache.ts │ │ ├── imageCache.ts │ │ ├── index.ts │ │ ├── offlineFallback.ts │ │ ├── pageCache.ts │ │ ├── staticResourceCache.ts │ │ └── warmStrategyCache.ts │ └── tsconfig.json ├── workbox-routing │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── NavigationRoute.ts │ │ ├── RegExpRoute.ts │ │ ├── Route.ts │ │ ├── Router.ts │ │ ├── _types.ts │ │ ├── _version.ts │ │ ├── index.ts │ │ ├── registerRoute.ts │ │ ├── setCatchHandler.ts │ │ ├── setDefaultHandler.ts │ │ └── utils │ │ │ ├── constants.ts │ │ │ ├── getOrCreateDefaultRouter.ts │ │ │ └── normalizeHandler.ts │ └── tsconfig.json ├── workbox-strategies │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── CacheFirst.ts │ │ ├── CacheOnly.ts │ │ ├── NetworkFirst.ts │ │ ├── NetworkOnly.ts │ │ ├── StaleWhileRevalidate.ts │ │ ├── Strategy.ts │ │ ├── StrategyHandler.ts │ │ ├── _version.ts │ │ ├── index.ts │ │ ├── plugins │ │ │ └── cacheOkAndOpaquePlugin.ts │ │ └── utils │ │ │ └── messages.ts │ └── tsconfig.json ├── workbox-streams │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── _types.ts │ │ ├── _version.ts │ │ ├── concatenate.ts │ │ ├── concatenateToResponse.ts │ │ ├── index.ts │ │ ├── isSupported.ts │ │ ├── strategy.ts │ │ └── utils │ │ │ └── createHeaders.ts │ └── tsconfig.json ├── workbox-sw │ ├── README.md │ ├── _types.mjs │ ├── _version.mjs │ ├── controllers │ │ └── WorkboxSW.mjs │ ├── index.mjs │ ├── package-lock.json │ └── package.json ├── workbox-webpack-plugin │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ │ ├── generate-sw.ts │ │ ├── index.ts │ │ ├── inject-manifest.ts │ │ └── lib │ │ │ ├── get-asset-hash.ts │ │ │ ├── get-manifest-entries-from-compilation.ts │ │ │ ├── get-script-files-for-chunks.ts │ │ │ ├── get-sourcemap-asset-name.ts │ │ │ ├── relative-to-output-path.ts │ │ │ └── resolve-webpack-url.ts │ └── tsconfig.json └── workbox-window │ ├── README.md │ ├── package-lock.json │ ├── package.json │ ├── src │ ├── Workbox.ts │ ├── _version.ts │ ├── index.ts │ ├── messageSW.ts │ └── utils │ │ ├── WorkboxEvent.ts │ │ ├── WorkboxEventTarget.ts │ │ └── urlsMatch.ts │ └── tsconfig.json ├── prettier.config.js ├── test ├── all │ └── node │ │ ├── test-exports.js │ │ ├── test-jsdocs.js │ │ ├── test-package.js │ │ ├── test-prod-builds.js │ │ └── test-yarn-installation.js ├── workbox-background-sync │ ├── integration │ │ └── test-all.js │ ├── static │ │ └── basic-example │ │ │ ├── example.txt │ │ │ ├── index.html │ │ │ └── sw.js │ └── sw │ │ ├── lib │ │ ├── test-QueueDb.mjs │ │ ├── test-QueueStore.mjs │ │ └── test-StorableRequest.mjs │ │ ├── test-BackgroundSyncPlugin.mjs │ │ └── test-Queue.mjs ├── workbox-broadcast-update │ ├── integration │ │ └── test-all.js │ ├── static │ │ ├── index.html │ │ └── sw.js │ └── sw │ │ ├── test-BroadcastCacheUpdate.mjs │ │ ├── test-BroadcastUpdatePlugin.mjs │ │ └── test-responsesAreSame.mjs ├── workbox-build │ ├── node │ │ ├── dependency-check.js │ │ ├── generate-sw.js │ │ ├── get-manifest.js │ │ ├── inject-manifest.js │ │ └── lib │ │ │ ├── additional-manifest-entries-transform.js │ │ │ ├── bundle.js │ │ │ ├── cdn-utils.js │ │ │ ├── copy-workbox-libraries.js │ │ │ ├── escape-regexp.js │ │ │ ├── get-composite-details.js │ │ │ ├── get-file-details.js │ │ │ ├── get-file-hash.js │ │ │ ├── get-file-manifest-entries.js │ │ │ ├── get-file-size.js │ │ │ ├── get-string-details.js │ │ │ ├── get-string-hash.js │ │ │ ├── modify-url-prefix-transform.js │ │ │ ├── module-registry.js │ │ │ ├── no-revision-for-urls-matching-transform.js │ │ │ ├── populate-sw-template.js │ │ │ ├── replace-and-update-source-map.js │ │ │ ├── runtime-caching-converter.js │ │ │ ├── transform-manifest.js │ │ │ ├── translate-url-to-sourcemap-paths.js │ │ │ ├── validate-options.js │ │ │ └── write-sw-using-default-template.js │ └── static │ │ ├── example-project-1 │ │ ├── .hidden-directory │ │ │ ├── hello.html │ │ │ └── hello.js │ │ ├── images │ │ │ ├── example-jpeg.jpg │ │ │ └── web-fundamentals-icon192x192.png │ │ ├── index.html │ │ ├── page-1.html │ │ ├── page-2.html │ │ ├── styles │ │ │ ├── stylesheet-1.css │ │ │ └── stylesheet-2.css │ │ └── webpackEntry.js │ │ ├── expected-source-map.js.map │ │ └── sw-injections │ │ ├── bad-multiple-injection.js │ │ ├── bad-no-injection.js │ │ ├── basic-with-invalid-sourcemap.js.nolint │ │ ├── basic-with-sourcemap-data-url.js.nolint │ │ ├── basic-with-sourcemap.js.map │ │ ├── basic-with-sourcemap.js.nolint │ │ ├── basic.js │ │ ├── custom-injection-point.js │ │ ├── multiple-calls.js │ │ ├── precache-and-route-options.js │ │ └── sample-import.js ├── workbox-cacheable-response │ ├── integration │ │ └── test-all.js │ ├── static │ │ └── cacheable-response-plugin │ │ │ ├── example-1.txt │ │ │ └── sw.js │ └── sw │ │ ├── test-CacheableResponse.mjs │ │ └── test-CacheableResponsePlugin.mjs ├── workbox-cli │ └── node │ │ ├── app.js │ │ ├── dependency-check.js │ │ └── lib │ │ ├── cleanup-stack-trace.js │ │ ├── help-text.js │ │ ├── logger.js │ │ ├── questions │ │ ├── ask-config-location.js │ │ ├── ask-extensions-to-cache.js │ │ ├── ask-questions.js │ │ ├── ask-root-of-web-app.js │ │ ├── ask-start_url-query-params.js │ │ ├── ask-sw-dest.js │ │ └── ask-sw-src.js │ │ └── run-wizard.js ├── workbox-core │ ├── integration │ │ └── test-all.js │ ├── static │ │ ├── core-in-browser │ │ │ ├── index.html │ │ │ └── sw.js │ │ └── logger.html │ └── sw │ │ ├── _private │ │ ├── test-Deferred.mjs │ │ ├── test-assert.mjs │ │ ├── test-cacheMatchIgnoreParams.mjs │ │ ├── test-executeQuotaErrorCallbacks.mjs │ │ ├── test-getFriendlyURL.mjs │ │ ├── test-logger.mjs │ │ ├── test-resultingClientExists.mjs │ │ ├── test-timeout.mjs │ │ └── test-waitUntil.mjs │ │ ├── models │ │ └── messages │ │ │ └── test-messageGenerator.mjs │ │ ├── test-cacheNames.mjs │ │ ├── test-clientsClaim.mjs │ │ ├── test-copyResponse.mjs │ │ ├── test-registerQuotaErrorCallback.mjs │ │ └── test-skipWaiting.mjs ├── workbox-expiration │ ├── integration │ │ └── test-all.js │ ├── static │ │ ├── expiration-plugin │ │ │ ├── example-1.txt │ │ │ ├── example-2.txt │ │ │ ├── sw-deletion.js │ │ │ ├── sw-max-age-seconds.js │ │ │ └── sw-max-entries.js │ │ └── isURLExpired.html │ └── sw │ │ ├── test-CacheExpiration.mjs │ │ ├── test-CacheTimestampsModel.mjs │ │ └── test-ExpirationPlugin.mjs ├── workbox-google-analytics │ ├── integration │ │ └── test-all.js │ ├── static │ │ └── basic-example │ │ │ ├── index.html │ │ │ └── sw.js │ └── sw │ │ └── test-initialize.mjs ├── workbox-navigation-preload │ ├── integration │ │ ├── test-disable.js │ │ ├── test-enable.js │ │ └── test-sw.js │ ├── static │ │ ├── sw-custom-header.js │ │ ├── sw-default-header.js │ │ └── sw-disable.js │ └── sw │ │ ├── test-disable.mjs │ │ ├── test-enable.mjs │ │ └── test-isSupported.mjs ├── workbox-precaching │ ├── integration │ │ ├── test-cleanup-outdated-caches.js │ │ ├── test-precache-and-update.js │ │ └── test-sw.js │ ├── static │ │ ├── addToCacheList.html │ │ ├── cleanup-outdated-caches │ │ │ ├── sw.js │ │ │ └── test.txt │ │ ├── precache-and-update │ │ │ ├── hashed-file.abcd1234.txt │ │ │ ├── index.html │ │ │ ├── styles │ │ │ │ └── index.css │ │ │ ├── sw-1.js │ │ │ └── sw-2.js │ │ ├── precache.html │ │ └── project │ │ │ ├── example-2.html │ │ │ ├── example-a.html │ │ │ ├── example-b.html │ │ │ ├── example-timestamp.html │ │ │ ├── example.html │ │ │ └── index.html │ └── sw │ │ ├── resetDefaultPrecacheController.mjs │ │ ├── test-PrecacheController.mjs │ │ ├── test-PrecacheFallbackPlugin.mjs │ │ ├── test-PrecacheRoute.mjs │ │ ├── test-PrecacheStrategy.mjs │ │ ├── test-addPlugins.mjs │ │ ├── test-addRoute.mjs │ │ ├── test-cleanupOutdatedCaches.mjs │ │ ├── test-createHandlerBoundToURL.mjs │ │ ├── test-getCacheKeyForURL.mjs │ │ ├── test-matchPrecache.mjs │ │ ├── test-precache.mjs │ │ ├── test-precacheAndRoute.mjs │ │ └── utils │ │ ├── test-deleteOutdatedCaches.mjs │ │ ├── test-printCleanupDetails.mjs │ │ └── test-printInstallDetails.mjs ├── workbox-range-requests │ ├── integration │ │ └── test-all.js │ ├── static │ │ ├── index.html │ │ └── sw.js │ └── sw │ │ ├── test-RangeRequestsPlugin.mjs │ │ ├── test-createPartialResponse.mjs │ │ └── utils │ │ ├── test-calculateEffectiveBoundaries.mjs │ │ └── test-parseRangeHeader.mjs ├── workbox-routing │ ├── integration │ │ ├── test-navigation-route.js │ │ ├── test-routing-basic.js │ │ ├── test-routing-regex.js │ │ └── test-sw.js │ ├── static │ │ ├── demo-img.png │ │ ├── routing-basic │ │ │ ├── index.html │ │ │ └── sw.js │ │ ├── routing-navigation │ │ │ ├── index.html │ │ │ └── sw.js │ │ ├── routing-regex │ │ │ ├── index.html │ │ │ └── sw.js │ │ ├── routing.html │ │ └── sw.js │ └── sw │ │ ├── test-NavigationRoute.mjs │ │ ├── test-RegExpRoute.mjs │ │ ├── test-Route.mjs │ │ ├── test-Router.mjs │ │ ├── test-registerRoute.mjs │ │ ├── test-setCatchHandler.mjs │ │ ├── test-setDefaultHandler.mjs │ │ └── utils │ │ └── test-normalizeHandler.mjs ├── workbox-strategies │ ├── integration │ │ ├── test-cacheFirst.js │ │ ├── test-cacheOnly.js │ │ ├── test-networkFirst.js │ │ ├── test-networkOnly.js │ │ ├── test-staleWhileRevalidate.js │ │ └── test-sw.js │ ├── static │ │ ├── cache-first │ │ │ ├── example.txt │ │ │ └── sw.js │ │ ├── cache-only │ │ │ └── sw.js │ │ ├── network-first │ │ │ └── sw.js │ │ ├── network-only │ │ │ └── sw.js │ │ └── stale-while-revalidate │ │ │ └── sw.js │ └── sw │ │ ├── plugins │ │ └── test-cacheOkAndOpaquePlugin.mjs │ │ ├── test-CacheFirst.mjs │ │ ├── test-CacheOnly.mjs │ │ ├── test-NetworkFirst.mjs │ │ ├── test-NetworkOnly.mjs │ │ ├── test-StaleWhileRevalidate.mjs │ │ ├── test-Strategy.mjs │ │ ├── test-StrategyHandler.mjs │ │ └── test-UsageWithRouter.mjs ├── workbox-streams │ ├── integration │ │ └── test-all.js │ ├── static │ │ ├── 4.txt │ │ ├── index.html │ │ └── sw.js │ └── sw │ │ ├── test-isSupported.mjs │ │ └── utils │ │ └── test-createHeaders.mjs ├── workbox-sw │ ├── integration │ │ └── test-all.js │ ├── static │ │ ├── example.css │ │ ├── example.js │ │ ├── index.html │ │ ├── integration │ │ │ ├── index.html │ │ │ ├── invalid-sw.js │ │ │ └── valid-sw.js │ │ └── sw.js │ └── sw │ │ └── controllers │ │ └── test-WorkboxSW.mjs ├── workbox-webpack-plugin │ ├── node │ │ ├── dependency-check.js │ │ ├── v4 │ │ │ ├── generate-sw.js │ │ │ ├── inject-manifest.js │ │ │ └── lib │ │ │ │ └── create-webpack-asset-plugin.js │ │ └── v5 │ │ │ ├── generate-sw.js │ │ │ ├── inject-manifest.js │ │ │ ├── lib │ │ │ └── create-webpack-asset-plugin.js │ │ │ └── static │ │ │ └── expected-service-worker.js.map │ └── static │ │ ├── bad-multiple-injection.js │ │ ├── example-project-1 │ │ ├── images │ │ │ ├── example-jpeg.jpg │ │ │ └── web-fundamentals-icon192x192.png │ │ ├── index.html │ │ ├── page-1.html │ │ ├── page-2.html │ │ ├── splitChunksEntry.js │ │ ├── styles │ │ │ ├── stylesheet-1.css │ │ │ └── stylesheet-2.css │ │ └── webpackEntry.js │ │ ├── expected-service-worker.js.map │ │ ├── injected-manifest.js │ │ ├── injected-manifest.json │ │ ├── module-import-sw.js │ │ ├── sw-src-define-plugin.js │ │ ├── sw-src-missing-sourcemap.js │ │ ├── sw-src.js │ │ ├── sw.ts │ │ └── wasm-project │ │ ├── add.wasm │ │ ├── index.js │ │ └── worker.js └── workbox-window │ ├── integration │ └── test-all.js │ ├── static │ └── index.html │ └── window │ ├── sw-error.js │ ├── sw-message-reply.js │ └── test-Workbox.mjs ├── tsconfig.json └── typescript.eslintrc.js /.gitattributes: -------------------------------------------------------------------------------- 1 | *.js text eol=lf 2 | *.mjs text eol=lf -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | Welcome! Please use this template for reporting bugs or requesting features. For questions about using Workbox, the best place to ask is Stack Overflow, tagged with `[workbox]`: https://stackoverflow.com/questions/ask?tags=workbox 2 | 3 | **Library Affected**: 4 | _workbox-sw, workbox-build, etc._ 5 | 6 | **Browser & Platform**: 7 | _E.g. Google Chrome v51.0.1 for Android, or "all browsers"._ 8 | 9 | **Issue or Feature Request Description**: 10 | _Your request here._ 11 | 12 | _When reporting bugs, please include relevant JavaScript Console logs and links to public URLs at which the issue could be reproduced._ 13 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | **Prior to creating a pull request, please follow all the steps in the [contributing guide](https://github.com/GoogleChrome/workbox/blob/v6/CONTRIBUTING.md).** 2 | 3 | Fixes #_issue number_ 4 | 5 | _Description of what's changed/fixed._ 6 | -------------------------------------------------------------------------------- /.husky/.gitignore: -------------------------------------------------------------------------------- 1 | _ 2 | -------------------------------------------------------------------------------- /.husky/pre-commit: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Please see https://typicode.github.io/husky/#/?id=command-not-found 4 | # if you have trouble running this command. 5 | 6 | . "$(dirname "$0")/_/husky.sh" 7 | 8 | npm run lint-staged 9 | -------------------------------------------------------------------------------- /.husky/pre-push: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # Please see https://typicode.github.io/husky/#/?id=command-not-found 4 | # if you have trouble running this command. 5 | 6 | . "$(dirname "$0")/_/husky.sh" 7 | 8 | npm run lint 9 | -------------------------------------------------------------------------------- /.ncurc.js: -------------------------------------------------------------------------------- 1 | // We use `npx npm-check-updates` to find updates to dependencies. 2 | // Some dependencies have breaking changes that we can't resolve. 3 | // This config file excludes those dependencies from the checks 4 | // until we're able to remediate our code to deal with them. 5 | 6 | module.exports = { 7 | reject: [ 8 | // See https://github.com/GoogleChrome/workbox/issues/2479 9 | 'service-worker-mock', 10 | ], 11 | }; 12 | -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | 20 2 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | _version.ts 2 | .nyc_output 3 | .vscode 4 | *.hbs 5 | *.log 6 | build 7 | coverage 8 | docs 9 | generated-release-files 10 | node_modules 11 | package-lock.json 12 | packages/**/*.d.ts 13 | packages/**/*.js 14 | packages/**/*.mjs 15 | packages/workbox-build/src/schema/*.json 16 | temp 17 | test/workbox-webpack-plugin/static/injected-manifest.json 18 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Code of Conduct 2 | 3 | All Google open source projects are covered by our [community guidelines](https://opensource.google/conduct/) which define the kind of respectful behavior we expect of all participants. 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2018 Google LLC 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. 20 | -------------------------------------------------------------------------------- /cdn-details.json: -------------------------------------------------------------------------------- 1 | { 2 | "origin": "https://storage.googleapis.com", 3 | "bucketName": "workbox-cdn", 4 | "releasesDir": "releases" 5 | } 6 | -------------------------------------------------------------------------------- /demos/README.md: -------------------------------------------------------------------------------- 1 | # workbox-module-demos 2 | 3 | Contains sample demos that are deployed to Glitch at https://glitch.com/@philkrie/workbox-demos and used as examples at https://developers.google.com/web/tools/workbox/modules 4 | -------------------------------------------------------------------------------- /demos/src/workbox-background-sync-demo/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "workbox-background-sync", 3 | "version": "1.0.0", 4 | "description": "Workbox Background Sync Demo Git Listener", 5 | "scripts": { 6 | "start": "node updateServer.js" 7 | }, 8 | "dependencies": { 9 | "express": "^4.17.1" 10 | }, 11 | "engines": { 12 | "node": "8.x" 13 | }, 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /demos/src/workbox-background-sync-demo/public/example.txt: -------------------------------------------------------------------------------- 1 | example text -------------------------------------------------------------------------------- /demos/src/workbox-background-sync-demo/sw.js: -------------------------------------------------------------------------------- 1 | importScripts( 2 | 'https://storage.googleapis.com/workbox-cdn/releases/6.1.5/workbox-sw.js', 3 | ); 4 | 5 | // Note: Ignore the error that Glitch raises about workbox being undefined. 6 | workbox.setConfig({ 7 | debug: true, 8 | }); 9 | 10 | const bgSyncPlugin = new workbox.backgroundSync.BackgroundSyncPlugin( 11 | 'myQueueName', 12 | ); 13 | 14 | workbox.routing.registerRoute( 15 | ({url}) => url.pathname === '/example.txt', 16 | new workbox.strategies.NetworkOnly({ 17 | plugins: [bgSyncPlugin], 18 | }), 19 | ); 20 | 21 | workbox.core.skipWaiting(); 22 | workbox.core.clientsClaim(); 23 | -------------------------------------------------------------------------------- /demos/src/workbox-broadcast-update-demo/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "workbox-broadcast-update", 3 | "version": "1.0.0", 4 | "description": "Workbox Broadcast Update Demo Git Listener", 5 | "scripts": { 6 | "start": "node updateServer.js" 7 | }, 8 | "dependencies": { 9 | "express": "^4.17.1" 10 | }, 11 | "engines": { 12 | "node": "8.x" 13 | }, 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /demos/src/workbox-cacheable-response/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "workbox-cacheable-response", 3 | "version": "1.0.0", 4 | "description": "Workbox Cacheable Response Demo Listener", 5 | "main": "server.js", 6 | "scripts": { 7 | "start": "node server.js" 8 | }, 9 | "dependencies": { 10 | "express": "^4.17.1" 11 | }, 12 | "engines": { 13 | "node": "8.x" 14 | }, 15 | "license": "MIT" 16 | } 17 | -------------------------------------------------------------------------------- /demos/src/workbox-cacheable-response/sw.js: -------------------------------------------------------------------------------- 1 | importScripts( 2 | 'https://storage.googleapis.com/workbox-cdn/releases/6.1.5/workbox-sw.js', 3 | ); 4 | 5 | workbox.setConfig({ 6 | debug: true, 7 | }); 8 | 9 | const cacheable = new workbox.cacheableResponse.CacheableResponse({ 10 | statuses: [200], 11 | headers: { 12 | 'X-Is-Cacheable': 'true', 13 | }, 14 | }); 15 | 16 | const handleCachableResponse = (event) => { 17 | return fetch(event.request).then((response) => { 18 | if (cacheable.isResponseCacheable(response)) { 19 | console.log('Response meets the criteria'); 20 | } else { 21 | console.log('Response does NOT meet the criteria'); 22 | } 23 | 24 | return response; 25 | }); 26 | }; 27 | 28 | self.addEventListener('fetch', (event) => { 29 | switch (new URL(event.request.url).pathname) { 30 | case '/api/is-response-cacheable': 31 | event.respondWith(handleCachableResponse(event)); 32 | break; 33 | } 34 | }); 35 | 36 | workbox.core.skipWaiting(); 37 | workbox.core.clientsClaim(); 38 | -------------------------------------------------------------------------------- /demos/src/workbox-core/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "workbox-core", 3 | "version": "1.0.0", 4 | "description": "Workbox Core Demo Git Listener", 5 | "scripts": { 6 | "start": "node updateServer.js" 7 | }, 8 | "dependencies": { 9 | "express": "^4.17.1" 10 | }, 11 | "engines": { 12 | "node": "8.x" 13 | }, 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /demos/src/workbox-expiration/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "workbox-expiration", 3 | "version": "1.0.0", 4 | "description": "Workbox Expiration Demo Git Listener", 5 | "scripts": { 6 | "start": "node updateServer.js" 7 | }, 8 | "dependencies": { 9 | "express": "^4.17.1" 10 | }, 11 | "engines": { 12 | "node": "8.x" 13 | }, 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /demos/src/workbox-google-analytics/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "workbox-google-analytics", 3 | "version": "1.0.0", 4 | "description": "Workbox Google Analytics Demo Git Listener", 5 | "scripts": { 6 | "start": "node updateServer.js" 7 | }, 8 | "dependencies": { 9 | "express": "^4.17.1" 10 | }, 11 | "engines": { 12 | "node": "8.x" 13 | }, 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /demos/src/workbox-google-analytics/sw.js: -------------------------------------------------------------------------------- 1 | importScripts( 2 | 'https://storage.googleapis.com/workbox-cdn/releases/6.1.5/workbox-sw.js', 3 | ); 4 | 5 | workbox.setConfig({ 6 | debug: true, 7 | }); 8 | 9 | workbox.googleAnalytics.initialize(); 10 | 11 | workbox.core.skipWaiting(); 12 | workbox.core.clientsClaim(); 13 | -------------------------------------------------------------------------------- /demos/src/workbox-navigation-preload/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "workbox-navigation-preload", 3 | "version": "1.0.0", 4 | "description": "Workbox Navigation Preload Demo Git Listener", 5 | "scripts": { 6 | "start": "node updateServer.js" 7 | }, 8 | "dependencies": { 9 | "express": "^4.17.1" 10 | }, 11 | "engines": { 12 | "node": "8.x" 13 | }, 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /demos/src/workbox-navigation-preload/sw.js: -------------------------------------------------------------------------------- 1 | importScripts( 2 | 'https://storage.googleapis.com/workbox-cdn/releases/6.1.5/workbox-sw.js', 3 | ); 4 | 5 | workbox.setConfig({ 6 | debug: true, 7 | }); 8 | 9 | // Enable navigation preload. 10 | workbox.navigationPreload.enable(); 11 | 12 | // Swap in NetworkOnly, CacheFirst, or StaleWhileRevalidate as needed. 13 | const strategy = new workbox.strategies.NetworkFirst({ 14 | cacheName: 'cached-navigations', 15 | plugins: [ 16 | // Any plugins, like workbox.expiration, etc. 17 | ], 18 | }); 19 | 20 | const navigationRoute = new workbox.routing.NavigationRoute(strategy, { 21 | // Optionally, provide a allowlist/denylist of RegExps to determine 22 | // which paths will match this route. 23 | // allowlist: [], 24 | // denylist: [], 25 | }); 26 | 27 | workbox.routing.registerRoute(navigationRoute); 28 | 29 | workbox.core.skipWaiting(); 30 | workbox.core.clientsClaim(); 31 | -------------------------------------------------------------------------------- /demos/src/workbox-precaching/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "workbox-precaching", 3 | "version": "1.0.0", 4 | "description": "Workbox Precaching Demo Git Listener", 5 | "scripts": { 6 | "start": "node updateServer.js" 7 | }, 8 | "dependencies": { 9 | "express": "^4.17.1" 10 | }, 11 | "engines": { 12 | "node": "8.x" 13 | }, 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /demos/src/workbox-precaching/public/hello-world.1234.txt: -------------------------------------------------------------------------------- 1 | Hello, World! 2 | 3 | I'm the first version of this file. -------------------------------------------------------------------------------- /demos/src/workbox-precaching/public/hello-world.5678.txt: -------------------------------------------------------------------------------- 1 | Hello, World! 2 | 3 | I'm the second version of this file. -------------------------------------------------------------------------------- /demos/src/workbox-precaching/public/test-file.txt: -------------------------------------------------------------------------------- 1 | #Danger 2 | 3 | This file is not revisioned. -------------------------------------------------------------------------------- /demos/src/workbox-precaching/sw-1.js: -------------------------------------------------------------------------------- 1 | importScripts( 2 | 'https://storage.googleapis.com/workbox-cdn/releases/6.1.5/workbox-sw.js', 3 | ); 4 | 5 | workbox.setConfig({ 6 | debug: true, 7 | }); 8 | 9 | workbox.precaching.precacheAndRoute([ 10 | {url: '/', revision: '1'}, 11 | {url: 'test-file.txt', revision: '1'}, 12 | 'hello-world.1234.txt', 13 | ]); 14 | -------------------------------------------------------------------------------- /demos/src/workbox-precaching/sw-2.js: -------------------------------------------------------------------------------- 1 | importScripts( 2 | 'https://storage.googleapis.com/workbox-cdn/releases/6.1.5/workbox-sw.js', 3 | ); 4 | 5 | workbox.setConfig({ 6 | debug: true, 7 | }); 8 | 9 | workbox.precaching.precacheAndRoute([ 10 | {url: '/', revision: '2'}, 11 | {url: 'test-file.txt', revision: '2'}, 12 | 'hello-world.5678.txt', 13 | ]); 14 | -------------------------------------------------------------------------------- /demos/src/workbox-range-requests/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "workbox-range-requests", 3 | "version": "1.0.0", 4 | "description": "Workbox Range Requests Demo Git Listener", 5 | "scripts": { 6 | "start": "node updateServer.js" 7 | }, 8 | "dependencies": { 9 | "express": "^4.17.1" 10 | }, 11 | "engines": { 12 | "node": "8.x" 13 | }, 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /demos/src/workbox-range-requests/sw.js: -------------------------------------------------------------------------------- 1 | importScripts( 2 | 'https://storage.googleapis.com/workbox-cdn/releases/6.1.5/workbox-sw.js', 3 | ); 4 | 5 | workbox.setConfig({ 6 | debug: true, 7 | }); 8 | 9 | workbox.routing.registerRoute( 10 | new RegExp('/range-request-example'), 11 | new workbox.strategies.CacheOnly({ 12 | cacheName: 'range-requests-demo', 13 | plugins: [new workbox.rangeRequests.RangeRequestsPlugin()], 14 | }), 15 | ); 16 | 17 | workbox.core.skipWaiting(); 18 | workbox.core.clientsClaim(); 19 | -------------------------------------------------------------------------------- /demos/src/workbox-routing/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "workbox-routing", 3 | "version": "1.0.0", 4 | "description": "Workbox Routing Demo Git Listener", 5 | "scripts": { 6 | "start": "node updateServer.js" 7 | }, 8 | "dependencies": { 9 | "express": "^4.17.1" 10 | }, 11 | "engines": { 12 | "node": "8.x" 13 | }, 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /demos/src/workbox-routing/public/demo-img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GoogleChrome/workbox/e26d8d7507f9412ba029922f3d9920e68710f2cf/demos/src/workbox-routing/public/demo-img.png -------------------------------------------------------------------------------- /demos/src/workbox-routing/public/demo-popper.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GoogleChrome/workbox/e26d8d7507f9412ba029922f3d9920e68710f2cf/demos/src/workbox-routing/public/demo-popper.png -------------------------------------------------------------------------------- /demos/src/workbox-strategies/public/cache-first.txt: -------------------------------------------------------------------------------- 1 | Hello from CacheFirst -------------------------------------------------------------------------------- /demos/src/workbox-strategies/public/network-first.txt: -------------------------------------------------------------------------------- 1 | Hello from NetworkFirst -------------------------------------------------------------------------------- /demos/src/workbox-strategies/public/network-only.txt: -------------------------------------------------------------------------------- 1 | Hello from NetworkOnly -------------------------------------------------------------------------------- /demos/src/workbox-strategies/public/stale-while-revalidate.txt: -------------------------------------------------------------------------------- 1 | Hello from StaleWhileRevalidate -------------------------------------------------------------------------------- /demos/src/workbox-streams/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "workbox-streams", 3 | "version": "1.0.0", 4 | "description": "Workbox Streams Demo Git Listener", 5 | "scripts": { 6 | "start": "node server.js" 7 | }, 8 | "dependencies": { 9 | "express": "^4.17.1" 10 | }, 11 | "engines": { 12 | "node": "8.x" 13 | }, 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /demos/src/workbox-sw/README.md: -------------------------------------------------------------------------------- 1 | # workbox-sw-demo 2 | -------------------------------------------------------------------------------- /demos/src/workbox-sw/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "workbox-sw", 3 | "version": "1.0.0", 4 | "description": "Workbox SW Demo Git Listener", 5 | "scripts": { 6 | "start": "node updateServer.js" 7 | }, 8 | "dependencies": { 9 | "express": "^4.17.1" 10 | }, 11 | "engines": { 12 | "node": "8.x" 13 | }, 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /demos/src/workbox-sw/public/demo-img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GoogleChrome/workbox/e26d8d7507f9412ba029922f3d9920e68710f2cf/demos/src/workbox-sw/public/demo-img.png -------------------------------------------------------------------------------- /demos/src/workbox-sw/sw.js: -------------------------------------------------------------------------------- 1 | importScripts( 2 | 'https://storage.googleapis.com/workbox-cdn/releases/6.1.5/workbox-sw.js', 3 | ); 4 | 5 | // Note: Ignore the error that Glitch raises about workbox being undefined. 6 | workbox.setConfig({ 7 | debug: true, 8 | }); 9 | 10 | workbox.precaching.precacheAndRoute([ 11 | 'https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css', 12 | ]); 13 | 14 | // Demonstrates using default cache 15 | workbox.routing.registerRoute( 16 | new RegExp('.*\\.(?:js)'), 17 | new workbox.strategies.NetworkFirst(), 18 | ); 19 | 20 | // Demonstrates a custom cache name for a route. 21 | workbox.routing.registerRoute( 22 | new RegExp('.*\\.(?:png|jpg|jpeg|svg|gif)'), 23 | new workbox.strategies.CacheFirst({ 24 | cacheName: 'image-cache', 25 | plugins: [ 26 | new workbox.expiration.ExpirationPlugin({ 27 | maxEntries: 3, 28 | }), 29 | ], 30 | }), 31 | ); 32 | -------------------------------------------------------------------------------- /demos/src/workbox-window/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "workbox-window", 3 | "version": "1.0.0", 4 | "description": "Workbox Window Demo Git Listener", 5 | "scripts": { 6 | "start": "node updateServer.js" 7 | }, 8 | "dependencies": { 9 | "express": "^4.17.1" 10 | }, 11 | "engines": { 12 | "node": "8.x" 13 | }, 14 | "license": "MIT" 15 | } 16 | -------------------------------------------------------------------------------- /demos/src/workbox-window/sw.js: -------------------------------------------------------------------------------- 1 | importScripts( 2 | 'https://storage.googleapis.com/workbox-cdn/releases/6.1.5/workbox-sw.js', 3 | ); 4 | 5 | workbox.setConfig({ 6 | debug: true, 7 | }); 8 | 9 | const SW_VERSION = '5.0.0'; 10 | 11 | addEventListener('message', (event) => { 12 | if (event.data.type === 'GET_VERSION') { 13 | event.ports[0].postMessage(SW_VERSION); 14 | } 15 | }); 16 | -------------------------------------------------------------------------------- /gulp-tasks/analyze-properties.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | const AnalyseBuildForProperties = require('./utils/analyse-properties'); 10 | 11 | async function analyze_properties() { 12 | const analysisTool = new AnalyseBuildForProperties(); 13 | const results = await analysisTool.run(); 14 | for (const result of results) { 15 | analysisTool.printDetails(result); 16 | } 17 | } 18 | 19 | module.exports = { 20 | analyze_properties, 21 | }; 22 | -------------------------------------------------------------------------------- /gulp-tasks/lint.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | const {parallel} = require('gulp'); 10 | const execa = require('execa'); 11 | 12 | async function lint_js() { 13 | await execa( 14 | 'eslint', 15 | [ 16 | '**/*.{js,mjs}', 17 | '--config', 18 | 'javascript.eslintrc.js', 19 | '--ignore-path', 20 | '.gitignore', 21 | ], 22 | {preferLocal: true}, 23 | ); 24 | } 25 | 26 | async function lint_ts() { 27 | await execa( 28 | 'eslint', 29 | [ 30 | '**/*.ts', 31 | '--config', 32 | 'typescript.eslintrc.js', 33 | '--ignore-path', 34 | '.gitignore', 35 | ], 36 | {preferLocal: true}, 37 | ); 38 | } 39 | 40 | module.exports = { 41 | lint_js, 42 | lint_ts, 43 | // Temporarily disable lint_ts until we upgrade our ESLint dependencies. 44 | lint: parallel(lint_js, lint_ts), 45 | }; 46 | -------------------------------------------------------------------------------- /gulp-tasks/test.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | const {parallel, series} = require('gulp'); 10 | 11 | const {lint} = require('./lint'); 12 | const {test_integration} = require('./test-integration'); 13 | const {test_node} = require('./test-node'); 14 | const logHelper = require('../infra/utils/log-helper'); 15 | 16 | async function logSkip() { 17 | logHelper.log('Skipping test suite due to --skipTests'); 18 | } 19 | 20 | function runTestsUnlessSkipped() { 21 | if (global.cliOptions.skipTests) { 22 | return logSkip; 23 | } else { 24 | // The node and integration tests both muck with process.env.NODE_ENV, 25 | // and therefore can't be run in parallel. 26 | return parallel(lint, series(test_node, test_integration)); 27 | } 28 | } 29 | 30 | module.exports = { 31 | test: runTestsUnlessSkipped(), 32 | }; 33 | -------------------------------------------------------------------------------- /gulp-tasks/utils/constants.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | module.exports = { 10 | // This is a directory that should not be commited 11 | // to git and will be removed and rebuilt between 12 | // test runs. 13 | PACKAGE_BUILD_DIRNAME: 'build', 14 | GENERATED_RELEASE_FILES_DIRNAME: 'generated-release-files', 15 | 16 | // This is used in the publish-bundle step to avoid doing anything 17 | // with tags that have known issues. 18 | MIN_RELEASE_TAG_TO_PUBLISH: 'v6.1.5', 19 | GITHUB_OWNER: 'GoogleChrome', 20 | GITHUB_REPO: 'workbox', 21 | 22 | // This is the environments that we should use for NODE_ENV. 23 | BUILD_TYPES: { 24 | dev: 'dev', 25 | prod: 'production', 26 | }, 27 | }; 28 | -------------------------------------------------------------------------------- /gulp-tasks/utils/get-packages.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | const {globSync} = require('glob'); 10 | const path = require('path'); 11 | 12 | const DEFAULT_ROOT = path.join(__dirname, '..', '..'); 13 | 14 | const getPackages = ({type, root = DEFAULT_ROOT} = {}) => { 15 | const pathToPkgJsons = globSync('packages/*/package.json', {cwd: root}); 16 | 17 | return pathToPkgJsons 18 | .map((pathToPkgJson) => { 19 | const pkg = require(`${path.resolve(root)}/${pathToPkgJson}`); 20 | return pkg; 21 | }) 22 | .filter((pkg) => { 23 | return pkg.workbox && pkg.workbox.packageType === type; 24 | }); 25 | }; 26 | 27 | module.exports = { 28 | getPackages, 29 | }; 30 | -------------------------------------------------------------------------------- /gulp-tasks/utils/node-projects-babel.config.json: -------------------------------------------------------------------------------- 1 | { 2 | "presets": [["@babel/preset-env", {"targets": {"node": "10.0"}}]] 3 | } 4 | -------------------------------------------------------------------------------- /gulp-tasks/utils/output-filename-to-package-map.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | const {getPackages} = require('./get-packages'); 10 | 11 | const outputFilenameToPkgMap = {}; 12 | 13 | const windowAndSWPackages = [ 14 | ...getPackages({type: 'sw'}), 15 | ...getPackages({type: 'window'}), 16 | ]; 17 | 18 | windowAndSWPackages.forEach((pkg) => { 19 | // When no `outputFilename` property exists, the package name is used. 20 | const outputFilename = pkg.workbox.outputFilename || pkg.name; 21 | 22 | outputFilenameToPkgMap[outputFilename] = pkg; 23 | }); 24 | 25 | module.exports = { 26 | outputFilenameToPkgMap, 27 | }; 28 | -------------------------------------------------------------------------------- /gulp-tasks/utils/pkg-path-to-name.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | const path = require('path'); 10 | 11 | const packagesPath = path.join(__dirname, '..', '..', 'packages'); 12 | 13 | // A helper method that should be used when you want to log 14 | // the package name ONLY. 15 | module.exports = (pkgPath) => { 16 | return path.relative(packagesPath, pkgPath); 17 | }; 18 | -------------------------------------------------------------------------------- /gulp-tasks/utils/versioned-cdn-url.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | const cdn = require('../../packages/workbox-build/src/cdn-details.json'); 10 | const lernaPkg = require('../../lerna.json'); 11 | 12 | module.exports = () => 13 | `${cdn.origin}/${cdn.bucketName}/${cdn.releasesDir}` + `/${lernaPkg.version}`; 14 | -------------------------------------------------------------------------------- /infra/templates/reference-docs/jsdoc/views/augments.hbs: -------------------------------------------------------------------------------- 1 | {{#any augments}} 2 |
{{translateHeading 'augments' augments}}
3 | {{#each augments}} 4 |
{{link this}}
5 | {{/each}} 6 | {{/any}} 7 | -------------------------------------------------------------------------------- /infra/templates/reference-docs/jsdoc/views/classes-links.hbs: -------------------------------------------------------------------------------- 1 | {{#any items}} 2 | {{translateHeading headingKey items}} 3 | 13 | {{/any}} 14 | -------------------------------------------------------------------------------- /infra/templates/reference-docs/jsdoc/views/details-table.hbs: -------------------------------------------------------------------------------- 1 | 2 | {{#block 'details-table-header'}} 3 | 4 | 11 | 12 | {{/block}} 13 | {{#block 'details-table-body'}} 14 | 15 | {{#each values}} 16 | {{#embed 'details-table-row'}}{{/embed}} 17 | {{/each}} 18 | 19 | {{/block}} 20 |
5 | {{#if isEnum}} 6 | {{translateHeading 'values' params}} 7 | {{else}} 8 | {{translateHeading 'parameters' params}} 9 | {{/if}} 10 |
21 | -------------------------------------------------------------------------------- /infra/templates/reference-docs/jsdoc/views/implements.hbs: -------------------------------------------------------------------------------- 1 | {{#any implements}} 2 |
{{translateHeading 'implements' implements}}
3 | {{#each implements}} 4 |
{{link this}}
5 | {{/each}} 6 | {{/any}} 7 | -------------------------------------------------------------------------------- /infra/templates/reference-docs/jsdoc/views/index-all.hbs: -------------------------------------------------------------------------------- 1 | {{#extend 'layout'}} 2 | {{#content 'title'}} 3 | Index All 4 | {{/content}} 5 | {{#content 'body-main-content'}} 6 | 11 | {{/content}} 12 | {{/extend}} 13 | -------------------------------------------------------------------------------- /infra/templates/reference-docs/jsdoc/views/index.hbs: -------------------------------------------------------------------------------- 1 | {{#extend 'layout'}} 2 | {{#content 'title'}} 3 | Overview 4 | {{/content}} 5 | {{#content 'body-main-content'}} 6 | {{#if readme}} 7 | {{{ readme }}} 8 | {{else}} 9 | {{#block 'body-symbol-index'}} 10 | {{#embed 'symbol-index'}}{{/embed}} 11 | {{/block}} 12 | {{/if}} 13 | {{/content}} 14 | {{/extend}} 15 | -------------------------------------------------------------------------------- /infra/templates/reference-docs/jsdoc/views/params.hbs: -------------------------------------------------------------------------------- 1 | {{#any params}} 2 |
3 | {{#withOnly values=(reparentItems this 'params')}} 4 | {{#embed 'details-table'}}{{/embed}} 5 | {{/withOnly}} 6 |
7 | {{/any}} 8 | -------------------------------------------------------------------------------- /infra/templates/reference-docs/jsdoc/views/properties.hbs: -------------------------------------------------------------------------------- 1 | {{#any (filterProperties properties)}} 2 |
3 | {{#unless isEnum}} 4 | {{translateHeading 'properties' properties}} 5 | {{/unless}} 6 | {{#withOnly values=(reparentItems this 'properties') isEnum=isEnum}} 7 | {{#embed 'details-table'}}{{/embed}} 8 | {{/withOnly}} 9 |
10 | {{/any}} 11 | -------------------------------------------------------------------------------- /infra/templates/reference-docs/jsdoc/views/see.hbs: -------------------------------------------------------------------------------- 1 | {{#any see}} 2 |
{{translateHeading 'see' see}}
3 | {{#each see}} 4 |
{{link (see this ../longname)}}
5 | {{/each}} 6 | {{/any}} 7 | -------------------------------------------------------------------------------- /infra/templates/reference-docs/jsdoc/views/signature.hbs: -------------------------------------------------------------------------------- 1 | {{!-- 2 | Note that this section omits the return type for: 3 | + Constructors 4 | + Methods with no explicit return type 5 | --}} 6 | {{#with symbol}} 7 | {{~#if (needsSignature this)~}} 8 | {{!-- CONSTRUCTOR PREFIX --}} 9 | {{#is kind 'class'}} 10 | {{#embed 'constructor-prefix'}}{{/embed}} 11 | {{/is}} 12 | {{name}}{{~formatParams params~}} 13 | {{~#isnt kind 'class'~}} 14 | {{~#if (returnTypes this)~}} 15 | {{~translate 'returnTypesSeparator'~}} 16 | {{describeType (returnTypes this)~}} 17 | {{~/if~}} 18 | {{~/isnt~}} 19 | {{~else~}} 20 | {{~#if type~}} 21 | {{~describeType type.parsedType~}} 22 | {{~/if~}} 23 | {{~/if~}} 24 | {{/with}} 25 | -------------------------------------------------------------------------------- /infra/templates/reference-docs/jsdoc/views/symbol-detail.hbs: -------------------------------------------------------------------------------- 1 | {{~#unless symbol.hideconstructor~}} 2 | 3 | {{~#with symbol~}} 4 | {{name}} 5 | {{~/with~}} 6 | 7 | {{~/unless~}} 8 | {{!-- 9 | Note that we omit the labels for classes, modules, and namespaces, since 10 | these labels would duplicate the labels for the page's main heading. 11 | --}} 12 | {{~#if symbol.kind~}} 13 | {{~#contains 'class' 'module' 'namespace' value=symbol.kind~}} 14 | {{~else~}} 15 | {{~#embed 'symbol-labels'}}{{/embed~}} 16 | {{~/contains~}} 17 | {{~/if~}} 18 | {{~#unless symbol.hideconstructor~}} 19 |

20 | {{~#embed 'signature'}}{{/embed~}} 21 |

22 | {{~/unless~}} 23 | {{#with symbol}} 24 | {{~#unless symbol.hideconstructor~}} 25 | {{#embed 'description'}}{{/embed}} 26 | {{#embed 'params'}}{{/embed}} 27 | {{#embed 'properties'}}{{/embed}} 28 |
29 | {{#embed 'details'}}{{/embed}} 30 |
31 | {{#embed 'examples'}}{{/embed}} 32 | {{~/unless~}} 33 | {{/with}} 34 | -------------------------------------------------------------------------------- /infra/templates/reference-docs/jsdoc/views/symbol-index-section.hbs: -------------------------------------------------------------------------------- 1 |
2 | {{#each doclets}} 3 |

4 | {{linkLongnameWithSignature this '!symbol-index-name'}} 5 |

6 | {{/each}} 7 |
8 | -------------------------------------------------------------------------------- /infra/templates/reference-docs/jsdoc/views/symbol-index.hbs: -------------------------------------------------------------------------------- 1 |
2 | {{#eachIndexGroup allLongnamesTree}} 3 |
4 |
5 | {{@groupName}} 6 |
7 | {{#each (group this 3)}} 8 | {{#withOnly doclets=this}} 9 | {{#embed 'symbol-index-section'}}{{/embed}} 10 | {{/withOnly}} 11 | {{/each}} 12 |
13 |
14 |
15 | {{/eachIndexGroup}} 16 |
17 | -------------------------------------------------------------------------------- /infra/templates/reference-docs/jsdoc/views/symbol-labels.hbs: -------------------------------------------------------------------------------- 1 | {{~#withOnly allLabels=(labels symbol)~}} 2 | {{~#any allLabels~}} 3 |
4 | {{~#each allLabels~}} 5 | {{text}} 6 | {{~#unless @last}}   {{/unless~}} 7 | {{~/each~}} 8 |
9 | {{~/any~}} 10 | {{~/withOnly~}} 11 | -------------------------------------------------------------------------------- /infra/templates/reference-docs/jsdoc/views/toc-yaml.hbs: -------------------------------------------------------------------------------- 1 | toc: 2 | {{#each symbols~}} 3 | - title: "{{tocYamlName}}" 4 | path: {{../basepath}}/{{basename (url longname) '.html'}} 5 | {{/each}} 6 | - title: "Index of all" 7 | path: {{basepath}}/index-all 8 | -------------------------------------------------------------------------------- /infra/testing/auto-stub-logger.mjs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import sinon from 'sinon'; 10 | import {logger} from '../../packages/workbox-core/_private/logger.mjs'; 11 | 12 | const sandbox = sinon.createSandbox(); 13 | const stubLogger = () => { 14 | // Logger will be `null` in production mode. 15 | if (logger) { 16 | sandbox.stub(logger); 17 | } 18 | }; 19 | 20 | // Silence any early messages (Normally caused by logging from an import at 21 | // the top of a test) 22 | stubLogger(); 23 | 24 | // This is part of the "root" mocha suite - meaning it'll reset all the logger 25 | // values before every test. 26 | beforeEach(function () { 27 | sandbox.restore(); 28 | 29 | stubLogger(); 30 | }); 31 | 32 | after(function () { 33 | sandbox.restore(); 34 | }); 35 | -------------------------------------------------------------------------------- /infra/testing/clean-sw.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | const runInSW = require('./comlink/node-interface'); 10 | 11 | module.exports = async (webdriver, testingURL) => { 12 | await webdriver.get(testingURL); 13 | try { 14 | await runInSW('clearAllCaches'); 15 | } catch (ignored) { 16 | // There might not yet be a service worker registered, in which case we 17 | // can't call runInSW(). 18 | } 19 | const error = await webdriver.executeAsyncScript((cb) => { 20 | navigator.serviceWorker 21 | .getRegistration() 22 | .then((reg) => { 23 | if (reg) { 24 | return reg.unregister(); 25 | } 26 | }) 27 | .then(() => cb()) 28 | .catch((err) => cb(err.message)); 29 | }); 30 | if (error) { 31 | throw new Error(error); 32 | } 33 | await webdriver.get(testingURL); 34 | }; 35 | -------------------------------------------------------------------------------- /infra/testing/comlink/node-interface.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | module.exports = async (command, ...args) => { 10 | const result = await global.__workbox.webdriver.executeAsyncScript( 11 | (command, args, cb) => { 12 | if (!('_runInSW' in window)) { 13 | cb({error: '_runInSW is not initialized.'}); 14 | } else { 15 | window._runInSW[command](...args) 16 | .then((result) => cb(result)) 17 | .catch((error) => 18 | cb({ 19 | error: `While running ${command}(${args}): ${error.message}`, 20 | }), 21 | ); 22 | } 23 | }, 24 | command, 25 | args, 26 | ); 27 | 28 | if (result instanceof Object && 'error' in result) { 29 | throw new Error(result.error); 30 | } 31 | return result; 32 | }; 33 | -------------------------------------------------------------------------------- /infra/testing/comlink/window-interface.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | function initComlink() { 10 | const channel = new MessageChannel(); 11 | navigator.serviceWorker.controller.postMessage(channel.port2, [ 12 | channel.port2, 13 | ]); 14 | window._runInSW = Comlink.wrap(channel.port1); 15 | channel.port1.start(); 16 | } 17 | 18 | const scriptEl = document.createElement('script'); 19 | scriptEl.src = '/__WORKBOX/comlink.js'; 20 | scriptEl.addEventListener('load', () => { 21 | if (navigator.serviceWorker.controller) { 22 | initComlink(); 23 | } 24 | navigator.serviceWorker.addEventListener('controllerchange', initComlink); 25 | }); 26 | document.body.appendChild(scriptEl); 27 | -------------------------------------------------------------------------------- /infra/testing/confirm-directory-contains.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | const expect = require('chai').expect; 10 | const globby = require('globby'); 11 | const upath = require('upath'); 12 | 13 | module.exports = async (directory, expectedContents) => { 14 | const relativeFiles = await globby('**', {cwd: directory}); 15 | const absoluteFilesWithNativeSeparator = relativeFiles.map((file) => 16 | upath.resolve(directory, file).replace(/\//g, upath.sep), 17 | ); 18 | expect(absoluteFilesWithNativeSeparator).to.have.members(expectedContents); 19 | }; 20 | -------------------------------------------------------------------------------- /infra/testing/expectError.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | const expect = require('chai').expect; 10 | const logHelper = require('../utils/log-helper'); 11 | 12 | module.exports = async (func, errorName, finalCb) => { 13 | let caughtError = null; 14 | try { 15 | const result = func(); 16 | if (result && result instanceof Promise) { 17 | await result; 18 | } 19 | } catch (err) { 20 | caughtError = err; 21 | } 22 | 23 | if (!caughtError) { 24 | throw new Error('Expected error to be thrown but function ran correctly.'); 25 | } 26 | 27 | if (caughtError.constructor.name !== 'WorkboxError') { 28 | logHelper.warn(`Unexpected error thrown.`, caughtError); 29 | } 30 | 31 | expect(caughtError.constructor.name).to.equal('WorkboxError'); 32 | expect(caughtError.name).to.equal(errorName); 33 | 34 | if (finalCb) { 35 | return finalCb(caughtError); 36 | } 37 | }; 38 | -------------------------------------------------------------------------------- /infra/testing/helpers/compareResponses.mjs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | const compareResponses = async (first, second, shouldBeSame) => { 10 | const firstBody = await first.clone().text(); 11 | const secondBody = await second.clone().text(); 12 | 13 | if (shouldBeSame) { 14 | expect(firstBody).to.equal(secondBody); 15 | } else { 16 | expect(firstBody).to.not.equal(secondBody); 17 | } 18 | }; 19 | 20 | export {compareResponses}; 21 | -------------------------------------------------------------------------------- /infra/testing/helpers/generateOpaqueResponse.mjs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | // Cache a resonse value and clone it instead of re-fetching every time. 10 | let response; 11 | 12 | export const generateOpaqueResponse = async () => { 13 | if (!response) { 14 | response = await fetch('https://google.com', {mode: 'no-cors'}); 15 | } 16 | return response.clone(); 17 | }; 18 | -------------------------------------------------------------------------------- /infra/testing/helpers/generateUniqueResponse.mjs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | let uid = 0; 10 | 11 | export const generateUniqueResponse = (responseInit = {}) => { 12 | return new Response(`${++uid}`, responseInit); 13 | }; 14 | -------------------------------------------------------------------------------- /infra/testing/helpers/sleep.mjs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | /** 10 | * Asynchronously waits for the passed number of milliseconds. 11 | * 12 | * @param {number} ms 13 | * @return {Promise} 14 | */ 15 | export const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms)); 16 | -------------------------------------------------------------------------------- /infra/testing/server/cross-origin-server.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | const express = require('express'); 10 | 11 | const PORT = 3010; 12 | 13 | let app; 14 | let server; 15 | 16 | function initApp(staticDir) { 17 | app = express(); 18 | app.use(express.static(staticDir)); 19 | } 20 | 21 | function start(staticDir) { 22 | if (!app) { 23 | initApp(staticDir); 24 | } 25 | 26 | return new Promise((resolve, reject) => { 27 | server = app.listen(PORT, (error) => { 28 | if (error) { 29 | reject(error); 30 | } else { 31 | resolve(`http://localhost:${PORT}`); 32 | } 33 | }); 34 | }); 35 | } 36 | 37 | function stop() { 38 | if (server) { 39 | server.close(); 40 | } 41 | } 42 | 43 | module.exports = { 44 | start, 45 | stop, 46 | }; 47 | -------------------------------------------------------------------------------- /infra/testing/server/routes/comlink.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | const match = '/__WORKBOX/comlink.js'; 10 | 11 | async function handler(req, res) { 12 | const comlinkMain = require.resolve('comlink'); 13 | res.sendFile(comlinkMain); 14 | } 15 | 16 | module.exports = { 17 | handler, 18 | match, 19 | }; 20 | -------------------------------------------------------------------------------- /infra/testing/server/routes/integration-html.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | const path = require('path'); 10 | 11 | const match = '/*/integration.html'; 12 | 13 | async function handler(req, res) { 14 | const filePath = path.join(__dirname, '..', 'static', 'integration.html'); 15 | res.sendFile(filePath); 16 | } 17 | 18 | module.exports = { 19 | handler, 20 | match, 21 | }; 22 | -------------------------------------------------------------------------------- /infra/testing/server/routes/templates-update.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | const templateData = require('../template-data'); 10 | 11 | // An endpoint to update template data from within tests. Any JSON in the 12 | // POST body will be merged with the existing template data. 13 | const match = '/__WORKBOX/updateTemplate'; 14 | 15 | async function handler(req, res) { 16 | templateData.assign(req.body); 17 | res.end(); 18 | } 19 | 20 | module.exports = { 21 | handler, 22 | match, 23 | method: 'post', 24 | }; 25 | -------------------------------------------------------------------------------- /infra/testing/server/routes/unique-etag.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | const match = '/__WORKBOX/uniqueETag'; 10 | 11 | let counter = 0; 12 | async function handler(req, res) { 13 | res.set('ETag', ++counter); 14 | res.send(`ETag is ${counter}.`); 15 | } 16 | 17 | module.exports = { 18 | handler, 19 | match, 20 | }; 21 | -------------------------------------------------------------------------------- /infra/testing/server/routes/unique-value.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | const match = '/__WORKBOX/uniqueValue'; 10 | 11 | let counter = 0; 12 | async function handler(req, res) { 13 | res.send(`Unique value is ${counter++}.`); 14 | } 15 | 16 | module.exports = { 17 | handler, 18 | match, 19 | }; 20 | -------------------------------------------------------------------------------- /infra/testing/server/static/integration.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Integration Test Harness 4 | 5 | 6 |

You need to manually register the service worker.

7 | 8 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /infra/testing/server/template-data.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | // We have to use global variables instead of local variables because 10 | // at the moment we're using `clear-require` to reset all modules between 11 | // tests, which means all local variables get reset, but globals persist. 12 | global.__uid = 0; 13 | global.__templateData = { 14 | ENV: process.env.NODE_ENV, 15 | uniqueID: () => { 16 | return ++global.__uid; 17 | }, 18 | }; 19 | 20 | const get = () => { 21 | return Object.assign({}, global.__templateData); 22 | }; 23 | 24 | const assign = (newData) => { 25 | Object.assign(global.__templateData, newData); 26 | }; 27 | 28 | module.exports = {get, assign}; 29 | -------------------------------------------------------------------------------- /infra/testing/server/templates/integration.html.njk: -------------------------------------------------------------------------------- 1 | 2 | 9 | 10 | 11 | 12 | {{ title }} 13 | 16 | 17 | 18 | {{ body }} 19 | 20 | 21 | -------------------------------------------------------------------------------- /infra/testing/server/templates/sw-clients-claim.js.njk: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | // {{ version }} 10 | 11 | addEventListener('install', (event) => event.waitUntil(skipWaiting())); 12 | addEventListener('activate', (event) => event.waitUntil( 13 | clients.claim().catch((error) => console.error(error)))); 14 | -------------------------------------------------------------------------------- /infra/testing/server/templates/sw-no-skip-waiting.js.njk: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | // {{ version }} 10 | -------------------------------------------------------------------------------- /infra/testing/server/templates/sw-script-version.js.njk: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | // {{ version }} 10 | 11 | addEventListener('install', (event) => event.waitUntil(skipWaiting())); 12 | addEventListener('activate', (event) => event.waitUntil(clients.claim())); 13 | 14 | addEventListener('message', async (event) => { 15 | // Assert the type and meta are correct. 16 | if (event.data.type === 'GET_VERSION' && 17 | event.data.meta === 'workbox-window') { 18 | event.ports[0].postMessage('{{ version }}'); 19 | } 20 | }); 21 | -------------------------------------------------------------------------------- /infra/testing/server/templates/sw-skip-waiting-deferred.js.njk: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | // {{ version }} 10 | 11 | addEventListener('install', (event) => { 12 | const doneInstalling = new Promise((resolve) => { 13 | setTimeout(() => { 14 | skipWaiting(); 15 | resolve(); 16 | }, 500); 17 | }); 18 | event.waitUntil(doneInstalling); 19 | }); 20 | -------------------------------------------------------------------------------- /infra/testing/server/templates/sw-skip-waiting-on-message.js.njk: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | // {{ version }} 10 | 11 | addEventListener('message', (event) => { 12 | if (event.data.type === 'SKIP_WAITING') { 13 | skipWaiting(); 14 | } 15 | }); 16 | -------------------------------------------------------------------------------- /infra/testing/server/templates/sw-skip-waiting.js.njk: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | // {{ version }} 10 | 11 | addEventListener('install', (event) => event.waitUntil(skipWaiting())); 12 | -------------------------------------------------------------------------------- /infra/testing/server/templates/sw-window-ready.js.njk: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | // {{ version }} 10 | 11 | addEventListener('install', (event) => event.waitUntil(skipWaiting())); 12 | addEventListener('activate', (event) => event.waitUntil(clients.claim())); 13 | 14 | addEventListener('message', async (event) => { 15 | // Assert the type and meta are correct. 16 | if (event.data.type === 'WINDOW_READY' && 17 | event.data.meta === 'workbox-window') { 18 | const windows = await clients.matchAll({ 19 | type: 'window', 20 | includeUncontrolled: true, 21 | }); 22 | for (const win of windows) { 23 | win.postMessage({type: 'sw:message:ready'}); 24 | } 25 | } 26 | }); 27 | -------------------------------------------------------------------------------- /infra/testing/wait-until.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | module.exports = async (fn, retries = 20, intervalMillis = 50) => { 10 | for (let i = 0; i < retries; i++) { 11 | const result = await fn(); 12 | if (result) { 13 | return; 14 | } 15 | await new Promise((resolve) => setTimeout(resolve, intervalMillis)); 16 | } 17 | throw new Error(`${fn} didn't return true after ${retries} retries.`); 18 | }; 19 | -------------------------------------------------------------------------------- /infra/testing/webdriver/executeAsyncAndCatch.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | // Store local references of these globals. 10 | const {webdriver} = global.__workbox; 11 | 12 | /** 13 | * Executes the passed function (and args) async and logs any errors that 14 | * occur. Errors are assumed to be passed to the callback as an object 15 | * with the `error` property. 16 | * 17 | * @param {...*} args 18 | * @return {*} 19 | */ 20 | const executeAsyncAndCatch = async (...args) => { 21 | const result = await webdriver.executeAsyncScript(...args); 22 | 23 | if (result && result.error) { 24 | console.error(result.error); 25 | throw new Error('Error executing async script'); 26 | } 27 | return result; 28 | }; 29 | 30 | module.exports = {executeAsyncAndCatch}; 31 | -------------------------------------------------------------------------------- /infra/testing/webdriver/unregisterAllSWs.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | const {executeAsyncAndCatch} = require('./executeAsyncAndCatch'); 10 | 11 | /** 12 | * Unregisters any active SWs so the next page load can start clean. 13 | * Note: a new page load is needed before controlling SWs stop being active. 14 | */ 15 | const unregisterAllSWs = async () => { 16 | await executeAsyncAndCatch(async (cb) => { 17 | try { 18 | const regs = await navigator.serviceWorker.getRegistrations(); 19 | for (const reg of regs) { 20 | await reg.unregister(); 21 | } 22 | cb(); 23 | } catch (error) { 24 | cb({error: error.stack}); 25 | } 26 | }); 27 | }; 28 | 29 | module.exports = {unregisterAllSWs}; 30 | -------------------------------------------------------------------------------- /infra/testing/webdriver/windowLoaded.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | const {executeAsyncAndCatch} = require('./executeAsyncAndCatch'); 10 | 11 | /** 12 | * Waits for the current window to load if it's not already loaded. 13 | */ 14 | const windowLoaded = async () => { 15 | // Wait for the window to load, so the `Workbox` global is available. 16 | await executeAsyncAndCatch(async (cb) => { 17 | const loaded = () => { 18 | if (!window.Workbox) { 19 | cb({ 20 | error: `window.Workbox is undefined; location is ${location.href}`, 21 | }); 22 | } else { 23 | cb(); 24 | } 25 | }; 26 | 27 | try { 28 | if (document.readyState === 'complete') { 29 | loaded(); 30 | } else { 31 | addEventListener('load', () => loaded()); 32 | } 33 | } catch (error) { 34 | cb({error: error.stack}); 35 | } 36 | }); 37 | }; 38 | 39 | module.exports = {windowLoaded}; 40 | -------------------------------------------------------------------------------- /infra/testing/webpack-build-check.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | function joinMessages(errorsOrWarnings) { 10 | if (errorsOrWarnings[0].message) { 11 | return errorsOrWarnings.map((item) => item.message).join('\n'); 12 | } else { 13 | return errorsOrWarnings.join('\n'); 14 | } 15 | } 16 | 17 | module.exports = (webpackError, stats) => { 18 | if (webpackError) { 19 | throw new Error(webpackError.message); 20 | } 21 | 22 | const statsJson = stats.toJson('verbose'); 23 | 24 | if (statsJson.errors.length > 0) { 25 | throw new Error(joinMessages(statsJson.errors)); 26 | } 27 | 28 | if (statsJson.warnings.length > 0) { 29 | throw new Error(joinMessages(statsJson.warnings)); 30 | } 31 | }; 32 | -------------------------------------------------------------------------------- /infra/utils/AsyncDebounce.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | class AsyncDebounce { 10 | constructor(fn) { 11 | this._fn = fn; 12 | this._needsRecall = false; 13 | } 14 | 15 | call() { 16 | if (!this._promise) { 17 | /* eslint-disable no-async-promise-executor */ 18 | this._promise = new Promise(async (resolve) => { 19 | do { 20 | this._needsRecall = false; 21 | await this._fn.call(); 22 | } while (this._needsRecall !== false); 23 | 24 | this._promise = null; 25 | resolve(); 26 | }); 27 | } else { 28 | this._needsRecall = true; 29 | } 30 | return this._promise; 31 | } 32 | } 33 | 34 | module.exports = {AsyncDebounce}; 35 | -------------------------------------------------------------------------------- /infra/utils/log-helper.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | const chalk = require('chalk'); 10 | 11 | const prefix = function () { 12 | return chalk.inverse(`[Workbox]:`); 13 | }; 14 | 15 | module.exports = { 16 | highlight: chalk.bgCyan, 17 | 18 | debug: (...args) => { 19 | console.log(prefix(), chalk.dim(...args)); 20 | }, 21 | 22 | log: (...args) => { 23 | console.log(prefix(), ...args); 24 | }, 25 | 26 | warn: (...args) => { 27 | console.warn(prefix(), chalk.yellow(...args)); 28 | }, 29 | 30 | error: (...args) => { 31 | console.error('\n'); 32 | console.error(prefix(), chalk.red(...args)); 33 | console.error('\n'); 34 | }, 35 | }; 36 | -------------------------------------------------------------------------------- /jsdoc.conf: -------------------------------------------------------------------------------- 1 | { 2 | "source": { 3 | "include": [ 4 | "packages" 5 | ], 6 | "exclude": [ 7 | "packages/workbox-cli" 8 | ], 9 | "includePattern": ".+\\.(js(doc|x)?|mjs)$", 10 | "excludePattern": "((^|\\/|\\\\)packages\\/.*\\/build(\\/|\\\\)|(^|\\/|\\\\)test(\\/|\\\\)|(^|\\/|\\\\)node_modules(\\/|\\\\)|(^|\\/|\\\\)demo(\\/|\\\\))" 11 | }, 12 | "opts": { 13 | "recurse": true 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "lerna": "5.6.2", 3 | "packages": ["packages/*"], 4 | "version": "7.3.0" 5 | } 6 | -------------------------------------------------------------------------------- /packages/workbox-background-sync/README.md: -------------------------------------------------------------------------------- 1 | This module's documentation can be found at https://developers.google.com/web/tools/workbox/modules/workbox-background-sync 2 | -------------------------------------------------------------------------------- /packages/workbox-background-sync/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "workbox-background-sync", 3 | "version": "7.3.0", 4 | "license": "MIT", 5 | "author": "Google's Web DevRel Team and Google's Aurora Team", 6 | "description": "Queues failed requests and uses the Background Sync API to replay them when the network is available", 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/googlechrome/workbox.git" 10 | }, 11 | "bugs": "https://github.com/googlechrome/workbox/issues", 12 | "homepage": "https://github.com/GoogleChrome/workbox", 13 | "keywords": [ 14 | "workbox", 15 | "workboxjs", 16 | "service worker", 17 | "sw", 18 | "background", 19 | "sync", 20 | "workbox-plugin" 21 | ], 22 | "workbox": { 23 | "browserNamespace": "workbox.backgroundSync", 24 | "packageType": "sw" 25 | }, 26 | "main": "index.js", 27 | "module": "index.mjs", 28 | "types": "index.d.ts", 29 | "dependencies": { 30 | "idb": "^7.0.1", 31 | "workbox-core": "7.3.0" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /packages/workbox-background-sync/src/QueueStore.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import './_version.js'; 10 | 11 | // This is a temporary workaround to expose something from ./lib/ via our 12 | // top-level public API. 13 | // TODO: In Workbox v7, move the actual code from ./lib/ to this file. 14 | export {QueueStore} from './lib/QueueStore'; 15 | -------------------------------------------------------------------------------- /packages/workbox-background-sync/src/StorableRequest.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import './_version.js'; 10 | 11 | // This is a temporary workaround to expose something from ./lib/ via our 12 | // top-level public API. 13 | // TODO: In Workbox v7, move the actual code from ./lib/ to this file. 14 | export {StorableRequest} from './lib/StorableRequest'; 15 | -------------------------------------------------------------------------------- /packages/workbox-background-sync/src/_version.ts: -------------------------------------------------------------------------------- 1 | // @ts-ignore 2 | try{self['workbox:background-sync:7.3.0']&&_()}catch(e){} -------------------------------------------------------------------------------- /packages/workbox-background-sync/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig", 3 | "compilerOptions": { 4 | "composite": true, 5 | "outDir": "./", 6 | "rootDir": "./src", 7 | "tsBuildInfoFile": "./tsconfig.tsbuildinfo" 8 | }, 9 | "include": ["src/**/*.ts"], 10 | "references": [{"path": "../workbox-core/"}] 11 | } 12 | -------------------------------------------------------------------------------- /packages/workbox-broadcast-update/README.md: -------------------------------------------------------------------------------- 1 | This module's documentation can be found at https://developers.google.com/web/tools/workbox/modules/workbox-broadcast-update 2 | -------------------------------------------------------------------------------- /packages/workbox-broadcast-update/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "workbox-broadcast-update", 3 | "version": "7.3.0", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "workbox-broadcast-update", 9 | "version": "7.3.0", 10 | "license": "MIT", 11 | "dependencies": { 12 | "workbox-core": "7.3.0" 13 | } 14 | }, 15 | "node_modules/workbox-core": { 16 | "version": "7.3.0", 17 | "resolved": "https://registry.npmjs.org/workbox-core/-/workbox-core-7.3.0.tgz", 18 | "integrity": "sha512-Z+mYrErfh4t3zi7NVTvOuACB0A/jA3bgxUN3PwtAVHvfEsZxV9Iju580VEETug3zYJRc0Dmii/aixI/Uxj8fmw==", 19 | "license": "MIT" 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /packages/workbox-broadcast-update/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "workbox-broadcast-update", 3 | "version": "7.3.0", 4 | "license": "MIT", 5 | "author": "Google's Web DevRel Team and Google's Aurora Team", 6 | "description": "A service worker helper library that uses the Broadcast Channel API to announce when a cached response has updated", 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/googlechrome/workbox.git" 10 | }, 11 | "bugs": "https://github.com/googlechrome/workbox/issues", 12 | "homepage": "https://github.com/GoogleChrome/workbox", 13 | "keywords": [ 14 | "workbox", 15 | "workboxjs", 16 | "service worker", 17 | "sw", 18 | "workbox-plugin" 19 | ], 20 | "workbox": { 21 | "browserNamespace": "workbox.broadcastUpdate", 22 | "packageType": "sw" 23 | }, 24 | "main": "index.js", 25 | "module": "index.mjs", 26 | "types": "index.d.ts", 27 | "dependencies": { 28 | "workbox-core": "7.3.0" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /packages/workbox-broadcast-update/src/_version.ts: -------------------------------------------------------------------------------- 1 | // @ts-ignore 2 | try{self['workbox:broadcast-update:7.3.0']&&_()}catch(e){} -------------------------------------------------------------------------------- /packages/workbox-broadcast-update/src/index.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import { 10 | BroadcastCacheUpdate, 11 | BroadcastCacheUpdateOptions, 12 | } from './BroadcastCacheUpdate.js'; 13 | import {BroadcastUpdatePlugin} from './BroadcastUpdatePlugin.js'; 14 | import {responsesAreSame} from './responsesAreSame.js'; 15 | 16 | import './_version.js'; 17 | 18 | /** 19 | * @module workbox-broadcast-update 20 | */ 21 | 22 | export { 23 | BroadcastCacheUpdate, 24 | BroadcastCacheUpdateOptions, 25 | BroadcastUpdatePlugin, 26 | responsesAreSame, 27 | }; 28 | -------------------------------------------------------------------------------- /packages/workbox-broadcast-update/src/utils/constants.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import '../_version.js'; 10 | 11 | export const CACHE_UPDATED_MESSAGE_TYPE = 'CACHE_UPDATED'; 12 | export const CACHE_UPDATED_MESSAGE_META = 'workbox-broadcast-update'; 13 | export const NOTIFY_ALL_CLIENTS = true; 14 | export const DEFAULT_HEADERS_TO_CHECK: string[] = [ 15 | 'content-length', 16 | 'etag', 17 | 'last-modified', 18 | ]; 19 | -------------------------------------------------------------------------------- /packages/workbox-broadcast-update/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig", 3 | "compilerOptions": { 4 | "composite": true, 5 | "outDir": "./", 6 | "rootDir": "./src", 7 | "tsBuildInfoFile": "./tsconfig.tsbuildinfo" 8 | }, 9 | "include": ["src/**/*.ts"], 10 | "references": [{"path": "../workbox-core/"}] 11 | } 12 | -------------------------------------------------------------------------------- /packages/workbox-build/.ncurc.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | // We use `npx npm-check-updates` to find updates to dependencies. 10 | // Some dependencies have breaking changes that we can't resolve. 11 | // This config file excludes those dependencies from the checks 12 | // until we're able to remediate our code to deal with them. 13 | module.exports = { 14 | reject: [ 15 | // joi v16 is the last release to support Node v10: 16 | // https://github.com/sideway/joi/issues/2262 17 | '@hapi/joi', 18 | ], 19 | }; 20 | -------------------------------------------------------------------------------- /packages/workbox-build/README.md: -------------------------------------------------------------------------------- 1 | This module's documentation can be found at https://developer.chrome.com/docs/workbox/modules/workbox-build 2 | -------------------------------------------------------------------------------- /packages/workbox-build/src/cdn-details.json: -------------------------------------------------------------------------------- 1 | { 2 | "origin": "https://storage.googleapis.com", 3 | "bucketName": "workbox-cdn", 4 | "releasesDir": "releases", 5 | "latestVersion": "7.3.0" 6 | } 7 | -------------------------------------------------------------------------------- /packages/workbox-build/src/index.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import {copyWorkboxLibraries} from './lib/copy-workbox-libraries'; 10 | import {getModuleURL} from './lib/cdn-utils'; 11 | import {generateSW} from './generate-sw'; 12 | import {getManifest} from './get-manifest'; 13 | import {injectManifest} from './inject-manifest'; 14 | 15 | /** 16 | * @module workbox-build 17 | */ 18 | export { 19 | copyWorkboxLibraries, 20 | generateSW, 21 | getManifest, 22 | getModuleURL, 23 | injectManifest, 24 | }; 25 | 26 | export * from './types'; 27 | -------------------------------------------------------------------------------- /packages/workbox-build/src/lib/escape-regexp.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | // From https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions 10 | export function escapeRegExp(str: string): string { 11 | return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); 12 | } 13 | -------------------------------------------------------------------------------- /packages/workbox-build/src/lib/get-composite-details.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import crypto from 'crypto'; 10 | 11 | import {FileDetails} from '../types'; 12 | 13 | export function getCompositeDetails( 14 | compositeURL: string, 15 | dependencyDetails: Array, 16 | ): FileDetails { 17 | let totalSize = 0; 18 | let compositeHash = ''; 19 | 20 | for (const fileDetails of dependencyDetails) { 21 | totalSize += fileDetails.size; 22 | compositeHash += fileDetails.hash; 23 | } 24 | 25 | const md5 = crypto.createHash('md5'); 26 | md5.update(compositeHash); 27 | const hashOfHashes = md5.digest('hex'); 28 | 29 | return { 30 | file: compositeURL, 31 | hash: hashOfHashes, 32 | size: totalSize, 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /packages/workbox-build/src/lib/get-file-hash.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import fse from 'fs-extra'; 10 | 11 | import {getStringHash} from './get-string-hash'; 12 | import {errors} from './errors'; 13 | 14 | export function getFileHash(file: string): string { 15 | try { 16 | const buffer = fse.readFileSync(file); 17 | return getStringHash(buffer); 18 | } catch (err) { 19 | throw new Error( 20 | errors['unable-to-get-file-hash'] + 21 | ` '${err instanceof Error && err.message ? err.message : ''}'`, 22 | ); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /packages/workbox-build/src/lib/get-file-size.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import fse from 'fs-extra'; 10 | 11 | import {errors} from './errors'; 12 | 13 | export function getFileSize(file: string): number | null { 14 | try { 15 | const stat = fse.statSync(file); 16 | if (!stat.isFile()) { 17 | return null; 18 | } 19 | return stat.size; 20 | } catch (err) { 21 | throw new Error( 22 | errors['unable-to-get-file-size'] + 23 | ` '${err instanceof Error && err.message ? err.message : ''}'`, 24 | ); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /packages/workbox-build/src/lib/get-source-map-url.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2022 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | // Adapted from https://github.com/lydell/source-map-url/blob/master/source-map-url.js 10 | // See https://github.com/GoogleChrome/workbox/issues/3019 11 | const innerRegex = /[#@] sourceMappingURL=([^\s'"]*)/; 12 | const regex = RegExp( 13 | '(?:' + 14 | '/\\*' + 15 | '(?:\\s*\r?\n(?://)?)?' + 16 | '(?:' + 17 | innerRegex.source + 18 | ')' + 19 | '\\s*' + 20 | '\\*/' + 21 | '|' + 22 | '//(?:' + 23 | innerRegex.source + 24 | ')' + 25 | ')' + 26 | '\\s*', 27 | ); 28 | 29 | export function getSourceMapURL(srcContents: string): string | null { 30 | const match = srcContents.match(regex); 31 | return match ? match[1] || match[2] || '' : null; 32 | } 33 | -------------------------------------------------------------------------------- /packages/workbox-build/src/lib/get-string-details.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import {FileDetails} from '../types'; 10 | import {getStringHash} from './get-string-hash'; 11 | 12 | export function getStringDetails(url: string, str: string): FileDetails { 13 | return { 14 | file: url, 15 | hash: getStringHash(str), 16 | size: str.length, 17 | }; 18 | } 19 | -------------------------------------------------------------------------------- /packages/workbox-build/src/lib/get-string-hash.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import crypto from 'crypto'; 10 | 11 | export function getStringHash(input: crypto.BinaryLike): string { 12 | const md5 = crypto.createHash('md5'); 13 | md5.update(input); 14 | return md5.digest('hex'); 15 | } 16 | -------------------------------------------------------------------------------- /packages/workbox-build/src/lib/maximum-size-transform.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import prettyBytes from 'pretty-bytes'; 10 | 11 | import {ManifestTransform} from '../types'; 12 | 13 | export function maximumSizeTransform( 14 | maximumFileSizeToCacheInBytes: number, 15 | ): ManifestTransform { 16 | return (originalManifest) => { 17 | const warnings: Array = []; 18 | const manifest = originalManifest.filter((entry) => { 19 | if (entry.size <= maximumFileSizeToCacheInBytes) { 20 | return true; 21 | } 22 | 23 | warnings.push( 24 | `${entry.url} is ${prettyBytes(entry.size)}, and won't ` + 25 | `be precached. Configure maximumFileSizeToCacheInBytes to change ` + 26 | `this limit.`, 27 | ); 28 | return false; 29 | }); 30 | 31 | return {manifest, warnings}; 32 | }; 33 | } 34 | -------------------------------------------------------------------------------- /packages/workbox-build/src/lib/no-revision-for-urls-matching-transform.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import {errors} from './errors'; 10 | import {ManifestTransform} from '../types'; 11 | 12 | export function noRevisionForURLsMatchingTransform( 13 | regexp: RegExp, 14 | ): ManifestTransform { 15 | if (!(regexp instanceof RegExp)) { 16 | throw new Error(errors['invalid-dont-cache-bust']); 17 | } 18 | 19 | return (originalManifest) => { 20 | const manifest = originalManifest.map((entry) => { 21 | if (typeof entry.url !== 'string') { 22 | throw new Error(errors['manifest-entry-bad-url']); 23 | } 24 | 25 | if (entry.url.match(regexp)) { 26 | entry.revision = null; 27 | } 28 | 29 | return entry; 30 | }); 31 | 32 | return {manifest}; 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /packages/workbox-build/src/lib/rebase-path.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import upath from 'upath'; 10 | 11 | export function rebasePath({ 12 | baseDirectory, 13 | file, 14 | }: { 15 | baseDirectory: string; 16 | file: string; 17 | }): string { 18 | // The initial path is relative to the current directory, so make it absolute. 19 | const absolutePath = upath.resolve(file); 20 | 21 | // Convert the absolute path so that it's relative to the baseDirectory. 22 | const relativePath = upath.relative(baseDirectory, absolutePath); 23 | 24 | // Remove any leading ./ as it won't work in a glob pattern. 25 | const normalizedPath = upath.normalize(relativePath); 26 | 27 | return normalizedPath; 28 | } 29 | -------------------------------------------------------------------------------- /packages/workbox-build/src/lib/stringify-without-comments.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2021 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import objectStringify from 'stringify-object'; 10 | import stripComments from 'strip-comments'; 11 | 12 | export function stringifyWithoutComments(obj: {[key: string]: any}): string { 13 | return objectStringify(obj, { 14 | // See https://github.com/yeoman/stringify-object#transformobject-property-originalresult 15 | transform: (_obj: {[key: string]: any}, _prop, str) => { 16 | if (typeof _prop !== 'symbol' && typeof _obj[_prop] === 'function') { 17 | // Can't typify correctly stripComments 18 | return stripComments(str); // eslint-disable-line 19 | } 20 | return str; 21 | }, 22 | }); 23 | } 24 | -------------------------------------------------------------------------------- /packages/workbox-build/src/rollup-plugin-off-main-thread.d.ts: -------------------------------------------------------------------------------- 1 | declare module '@surma/rollup-plugin-off-main-thread'; 2 | -------------------------------------------------------------------------------- /packages/workbox-build/src/strip-comments.d.ts: -------------------------------------------------------------------------------- 1 | declare module 'strip-comments'; 2 | -------------------------------------------------------------------------------- /packages/workbox-build/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig", 3 | "compilerOptions": { 4 | "composite": true, 5 | "esModuleInterop": true, 6 | "module": "CommonJS", 7 | "outDir": "./build", 8 | "resolveJsonModule": true, 9 | "rootDir": "./src", 10 | "target": "ES2018", 11 | "tsBuildInfoFile": "./tsconfig.tsbuildinfo" 12 | }, 13 | "files": ["src/cdn-details.json"], 14 | "include": ["src/**/*.ts", "src/schema/*.json"], 15 | "references": [ 16 | {"path": "../workbox-background-sync/"}, 17 | {"path": "../workbox-broadcast-update/"}, 18 | {"path": "../workbox-cacheable-response/"}, 19 | {"path": "../workbox-core/"}, 20 | {"path": "../workbox-expiration/"}, 21 | {"path": "../workbox-google-analytics/"} 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /packages/workbox-cacheable-response/README.md: -------------------------------------------------------------------------------- 1 | This module's documentation can be found at https://developers.google.com/web/tools/workbox/modules/workbox-cacheable-response 2 | -------------------------------------------------------------------------------- /packages/workbox-cacheable-response/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "workbox-cacheable-response", 3 | "version": "7.3.0", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "workbox-cacheable-response", 9 | "version": "7.3.0", 10 | "license": "MIT", 11 | "dependencies": { 12 | "workbox-core": "7.3.0" 13 | } 14 | }, 15 | "node_modules/workbox-core": { 16 | "version": "7.3.0", 17 | "resolved": "https://registry.npmjs.org/workbox-core/-/workbox-core-7.3.0.tgz", 18 | "integrity": "sha512-Z+mYrErfh4t3zi7NVTvOuACB0A/jA3bgxUN3PwtAVHvfEsZxV9Iju580VEETug3zYJRc0Dmii/aixI/Uxj8fmw==", 19 | "license": "MIT" 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /packages/workbox-cacheable-response/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "workbox-cacheable-response", 3 | "version": "7.3.0", 4 | "license": "MIT", 5 | "author": "Google's Web DevRel Team and Google's Aurora Team", 6 | "description": "This library takes a Response object and determines whether it's cacheable based on a specific configuration.", 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/googlechrome/workbox.git" 10 | }, 11 | "bugs": "https://github.com/googlechrome/workbox/issues", 12 | "homepage": "https://github.com/GoogleChrome/workbox", 13 | "keywords": [ 14 | "workbox", 15 | "workboxjs", 16 | "service worker", 17 | "sw", 18 | "workbox-plugin" 19 | ], 20 | "workbox": { 21 | "browserNamespace": "workbox.cacheableResponse", 22 | "packageType": "sw" 23 | }, 24 | "main": "index.js", 25 | "module": "index.mjs", 26 | "types": "index.d.ts", 27 | "dependencies": { 28 | "workbox-core": "7.3.0" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /packages/workbox-cacheable-response/src/_version.ts: -------------------------------------------------------------------------------- 1 | // @ts-ignore 2 | try{self['workbox:cacheable-response:7.3.0']&&_()}catch(e){} -------------------------------------------------------------------------------- /packages/workbox-cacheable-response/src/index.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import { 10 | CacheableResponse, 11 | CacheableResponseOptions, 12 | } from './CacheableResponse.js'; 13 | import {CacheableResponsePlugin} from './CacheableResponsePlugin.js'; 14 | 15 | import './_version.js'; 16 | 17 | /** 18 | * @module workbox-cacheable-response 19 | */ 20 | 21 | export {CacheableResponse, CacheableResponseOptions, CacheableResponsePlugin}; 22 | -------------------------------------------------------------------------------- /packages/workbox-cacheable-response/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig", 3 | "compilerOptions": { 4 | "composite": true, 5 | "outDir": "./", 6 | "rootDir": "./src", 7 | "tsBuildInfoFile": "./tsconfig.tsbuildinfo" 8 | }, 9 | "include": ["src/**/*.ts"], 10 | "references": [{"path": "../workbox-core/"}] 11 | } 12 | -------------------------------------------------------------------------------- /packages/workbox-cli/README.md: -------------------------------------------------------------------------------- 1 | This module's documentation can be found at https://developers.google.com/web/tools/workbox/modules/workbox-cli 2 | -------------------------------------------------------------------------------- /packages/workbox-cli/src/lib/cleanup-stack-trace.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | // Helper to parse out less relevant info from an Error's stack trace. 10 | // Removes the initial portion, since that's obtained from error.message. 11 | // Removes every stack frame earlier than the last instance of moduleName, 12 | // since that's just frames related to the Node runtime/loader. 13 | export function cleanupStackTrace(error: Error, moduleName: string): string { 14 | if (!error.stack) { 15 | return ''; 16 | } 17 | const frames = error.stack.split(`\n`); 18 | let startFrame: number | undefined; 19 | let lastFrame = 0; 20 | frames.forEach((frame, index) => { 21 | if (startFrame === undefined && frame.includes(` at `)) { 22 | startFrame = index; 23 | } 24 | 25 | if (frame.includes(`${moduleName}:`)) { 26 | lastFrame = index; 27 | } 28 | }); 29 | return frames.slice(startFrame, lastFrame + 1).join(`\n`); 30 | } 31 | -------------------------------------------------------------------------------- /packages/workbox-cli/src/lib/constants.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | export const constants = { 10 | defaultConfigFile: 'workbox-config.js', 11 | ignoredDirectories: ['node_modules'], 12 | ignoredFileExtensions: ['map'], 13 | ignoreURLParametersMatching: [/^utm_/, /^fbclid$/], 14 | }; 15 | -------------------------------------------------------------------------------- /packages/workbox-cli/src/lib/logger.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import chalk from 'chalk'; 10 | 11 | export const logger = { 12 | debug: (...args: string[]): void => console.log(chalk.gray(...args)), 13 | log: (...args: string[]): void => console.log(...args), 14 | warn: (...args: string[]): void => console.warn(chalk.yellow(...args)), 15 | error: (...args: string[]): void => console.error(chalk.red.bold(...args)), 16 | }; 17 | -------------------------------------------------------------------------------- /packages/workbox-cli/src/lib/questions/ask-sw-src.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import {Answers} from 'inquirer'; 10 | import inquirer from 'inquirer'; 11 | import {oneLine as ol} from 'common-tags'; 12 | 13 | // The key used for the question/answer. 14 | const name = 'swSrc'; 15 | 16 | /** 17 | * @return {Promise} The answers from inquirer. 18 | */ 19 | function askQuestion(): Promise { 20 | return inquirer.prompt([ 21 | { 22 | name, 23 | message: ol`Where's your existing service worker file? To be used with 24 | injectManifest, it should include a call to 25 | 'self.__WB_MANIFEST'`, 26 | type: 'input', 27 | }, 28 | ]); 29 | } 30 | 31 | export async function askSWSrc(): Promise { 32 | const answers = await askQuestion(); 33 | // When prompt type is input the return is string or null 34 | return answers[name] ? (answers[name] as string).trim() : null; 35 | } 36 | -------------------------------------------------------------------------------- /packages/workbox-cli/src/lib/read-config.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import {GenerateSWOptions, InjectManifestOptions} from 'workbox-build'; 10 | 11 | // A really light wrapper on top of Node's require() to make it easier to stub 12 | // out reading the configuration during tests. 13 | export function readConfig( 14 | configFile: string, 15 | ): GenerateSWOptions | InjectManifestOptions { 16 | return require(configFile) as GenerateSWOptions | InjectManifestOptions; 17 | } 18 | -------------------------------------------------------------------------------- /packages/workbox-cli/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig", 3 | "compilerOptions": { 4 | "esModuleInterop": true, 5 | "module": "CommonJS", 6 | "outDir": "build", 7 | "rootDir": "src", 8 | "target": "ES2018", 9 | "tsBuildInfoFile": "./tsconfig.tsbuildinfo" 10 | }, 11 | "include": ["src/**/*.ts"], 12 | "references": [{"path": "../workbox-build/"}] 13 | } 14 | -------------------------------------------------------------------------------- /packages/workbox-core/README.md: -------------------------------------------------------------------------------- 1 | This module's documentation can be found at https://developers.google.com/web/tools/workbox/modules/workbox-core 2 | -------------------------------------------------------------------------------- /packages/workbox-core/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "workbox-core", 3 | "version": "7.3.0", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "workbox-core", 9 | "version": "7.3.0", 10 | "license": "MIT" 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/workbox-core/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "workbox-core", 3 | "version": "7.3.0", 4 | "license": "MIT", 5 | "author": "Google's Web DevRel Team and Google's Aurora Team", 6 | "description": "This module is used by a number of the other Workbox modules to share common code.", 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/googlechrome/workbox.git" 10 | }, 11 | "bugs": "https://github.com/googlechrome/workbox/issues", 12 | "homepage": "https://github.com/GoogleChrome/workbox", 13 | "keywords": [ 14 | "workbox", 15 | "workboxjs", 16 | "service worker", 17 | "sw" 18 | ], 19 | "workbox": { 20 | "browserNamespace": "workbox.core", 21 | "packageType": "sw" 22 | }, 23 | "main": "index.js", 24 | "module": "index.mjs", 25 | "types": "index.d.ts" 26 | } 27 | -------------------------------------------------------------------------------- /packages/workbox-core/src/_private/Deferred.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import '../_version.js'; 10 | 11 | /** 12 | * The Deferred class composes Promises in a way that allows for them to be 13 | * resolved or rejected from outside the constructor. In most cases promises 14 | * should be used directly, but Deferreds can be necessary when the logic to 15 | * resolve a promise must be separate. 16 | * 17 | * @private 18 | */ 19 | class Deferred { 20 | promise: Promise; 21 | resolve!: (value: T) => void; 22 | reject!: (reason?: any) => void; 23 | 24 | /** 25 | * Creates a promise and exposes its resolve and reject functions as methods. 26 | */ 27 | constructor() { 28 | this.promise = new Promise((resolve, reject) => { 29 | this.resolve = resolve; 30 | this.reject = reject; 31 | }); 32 | } 33 | } 34 | 35 | export {Deferred}; 36 | -------------------------------------------------------------------------------- /packages/workbox-core/src/_private/dontWaitFor.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | Use of this source code is governed by an MIT-style 4 | license that can be found in the LICENSE file or at 5 | https://opensource.org/licenses/MIT. 6 | */ 7 | 8 | import '../_version.js'; 9 | 10 | /** 11 | * A helper function that prevents a promise from being flagged as unused. 12 | * 13 | * @private 14 | **/ 15 | export function dontWaitFor(promise: Promise): void { 16 | // Effective no-op. 17 | void promise.then(() => {}); 18 | } 19 | -------------------------------------------------------------------------------- /packages/workbox-core/src/_private/getFriendlyURL.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import '../_version.js'; 10 | 11 | const getFriendlyURL = (url: URL | string): string => { 12 | const urlObj = new URL(String(url), location.href); 13 | // See https://github.com/GoogleChrome/workbox/issues/2323 14 | // We want to include everything, except for the origin if it's same-origin. 15 | return urlObj.href.replace(new RegExp(`^${location.origin}`), ''); 16 | }; 17 | 18 | export {getFriendlyURL}; 19 | -------------------------------------------------------------------------------- /packages/workbox-core/src/_private/timeout.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | Use of this source code is governed by an MIT-style 4 | license that can be found in the LICENSE file or at 5 | https://opensource.org/licenses/MIT. 6 | */ 7 | 8 | import '../_version.js'; 9 | 10 | /** 11 | * Returns a promise that resolves and the passed number of milliseconds. 12 | * This utility is an async/await-friendly version of `setTimeout`. 13 | * 14 | * @param {number} ms 15 | * @return {Promise} 16 | * @private 17 | */ 18 | 19 | export function timeout(ms: number): Promise { 20 | return new Promise((resolve) => setTimeout(resolve, ms)); 21 | } 22 | -------------------------------------------------------------------------------- /packages/workbox-core/src/_private/waitUntil.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Google LLC 3 | Use of this source code is governed by an MIT-style 4 | license that can be found in the LICENSE file or at 5 | https://opensource.org/licenses/MIT. 6 | */ 7 | 8 | import '../_version.js'; 9 | 10 | /** 11 | * A utility method that makes it easier to use `event.waitUntil` with 12 | * async functions and return the result. 13 | * 14 | * @param {ExtendableEvent} event 15 | * @param {Function} asyncFn 16 | * @return {Function} 17 | * @private 18 | */ 19 | function waitUntil( 20 | event: ExtendableEvent, 21 | asyncFn: () => Promise, 22 | ): Promise { 23 | const returnPromise = asyncFn(); 24 | event.waitUntil(returnPromise); 25 | return returnPromise; 26 | } 27 | 28 | export {waitUntil}; 29 | -------------------------------------------------------------------------------- /packages/workbox-core/src/_version.ts: -------------------------------------------------------------------------------- 1 | // @ts-ignore 2 | try{self['workbox:core:7.3.0']&&_()}catch(e){} -------------------------------------------------------------------------------- /packages/workbox-core/src/clientsClaim.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import './_version.js'; 10 | 11 | // Give TypeScript the correct global. 12 | declare let self: ServiceWorkerGlobalScope; 13 | 14 | /** 15 | * Claim any currently available clients once the service worker 16 | * becomes active. This is normally used in conjunction with `skipWaiting()`. 17 | * 18 | * @memberof workbox-core 19 | */ 20 | function clientsClaim(): void { 21 | self.addEventListener('activate', () => self.clients.claim()); 22 | } 23 | 24 | export {clientsClaim}; 25 | -------------------------------------------------------------------------------- /packages/workbox-core/src/index.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import {registerQuotaErrorCallback} from './registerQuotaErrorCallback.js'; 10 | import * as _private from './_private.js'; 11 | import {cacheNames} from './cacheNames.js'; 12 | import {copyResponse} from './copyResponse.js'; 13 | import {clientsClaim} from './clientsClaim.js'; 14 | import {setCacheNameDetails} from './setCacheNameDetails.js'; 15 | import {skipWaiting} from './skipWaiting.js'; 16 | import './_version.js'; 17 | 18 | /** 19 | * All of the Workbox service worker libraries use workbox-core for shared 20 | * code as well as setting default values that need to be shared (like cache 21 | * names). 22 | * 23 | * @module workbox-core 24 | */ 25 | export { 26 | _private, 27 | cacheNames, 28 | clientsClaim, 29 | copyResponse, 30 | registerQuotaErrorCallback, 31 | setCacheNameDetails, 32 | skipWaiting, 33 | }; 34 | 35 | export * from './types.js'; 36 | -------------------------------------------------------------------------------- /packages/workbox-core/src/models/messages/messageGenerator.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import {messages} from './messages.js'; 10 | import '../../_version.js'; 11 | 12 | const fallback = (code: string, ...args: any[]) => { 13 | let msg = code; 14 | if (args.length > 0) { 15 | msg += ` :: ${JSON.stringify(args)}`; 16 | } 17 | return msg; 18 | }; 19 | 20 | const generatorFunction = (code: string, details = {}) => { 21 | const message = messages[code]; 22 | if (!message) { 23 | throw new Error(`Unable to find message for code '${code}'.`); 24 | } 25 | 26 | return message(details); 27 | }; 28 | 29 | export const messageGenerator = 30 | process.env.NODE_ENV === 'production' ? fallback : generatorFunction; 31 | -------------------------------------------------------------------------------- /packages/workbox-core/src/models/pluginEvents.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import '../_version.js'; 10 | 11 | export const enum pluginEvents { 12 | CACHE_DID_UPDATE = 'cacheDidUpdate', 13 | CACHE_KEY_WILL_BE_USED = 'cacheKeyWillBeUsed', 14 | CACHE_WILL_UPDATE = 'cacheWillUpdate', 15 | CACHED_RESPONSE_WILL_BE_USED = 'cachedResponseWillBeUsed', 16 | FETCH_DID_FAIL = 'fetchDidFail', 17 | FETCH_DID_SUCCEED = 'fetchDidSucceed', 18 | REQUEST_WILL_FETCH = 'requestWillFetch', 19 | } 20 | -------------------------------------------------------------------------------- /packages/workbox-core/src/models/quotaErrorCallbacks.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import '../_version.js'; 10 | 11 | // Callbacks to be executed whenever there's a quota error. 12 | // Can't change Function type right now. 13 | // eslint-disable-next-line @typescript-eslint/ban-types 14 | const quotaErrorCallbacks: Set = new Set(); 15 | 16 | export {quotaErrorCallbacks}; 17 | -------------------------------------------------------------------------------- /packages/workbox-core/src/utils/pluginUtils.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import {WorkboxPlugin} from '../types.js'; 10 | import '../_version.js'; 11 | 12 | export const pluginUtils = { 13 | filter: (plugins: WorkboxPlugin[], callbackName: string): WorkboxPlugin[] => { 14 | return plugins.filter((plugin) => callbackName in plugin); 15 | }, 16 | }; 17 | -------------------------------------------------------------------------------- /packages/workbox-core/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig", 3 | "compilerOptions": { 4 | "composite": true, 5 | "outDir": "./", 6 | "rootDir": "./src", 7 | "tsBuildInfoFile": "./tsconfig.tsbuildinfo" 8 | }, 9 | "include": ["src/**/*.ts"] 10 | } 11 | -------------------------------------------------------------------------------- /packages/workbox-expiration/README.md: -------------------------------------------------------------------------------- 1 | This module's documentation can be found at https://developers.google.com/web/tools/workbox/modules/workbox-expiration 2 | -------------------------------------------------------------------------------- /packages/workbox-expiration/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "workbox-expiration", 3 | "version": "7.3.0", 4 | "license": "MIT", 5 | "author": "Google's Web DevRel Team and Google's Aurora Team", 6 | "description": "A service worker helper library that expires cached responses based on age or maximum number of entries.", 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/googlechrome/workbox.git" 10 | }, 11 | "bugs": "https://github.com/googlechrome/workbox/issues", 12 | "homepage": "https://github.com/GoogleChrome/workbox", 13 | "keywords": [ 14 | "workbox", 15 | "workboxjs", 16 | "service worker", 17 | "sw", 18 | "workbox-plugin" 19 | ], 20 | "workbox": { 21 | "browserNamespace": "workbox.expiration", 22 | "packageType": "sw" 23 | }, 24 | "main": "index.js", 25 | "module": "index.mjs", 26 | "types": "index.d.ts", 27 | "dependencies": { 28 | "idb": "^7.0.1", 29 | "workbox-core": "7.3.0" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /packages/workbox-expiration/src/_version.ts: -------------------------------------------------------------------------------- 1 | // @ts-ignore 2 | try{self['workbox:expiration:7.3.0']&&_()}catch(e){} -------------------------------------------------------------------------------- /packages/workbox-expiration/src/index.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import {CacheExpiration} from './CacheExpiration.js'; 10 | import {ExpirationPlugin, ExpirationPluginOptions} from './ExpirationPlugin.js'; 11 | 12 | import './_version.js'; 13 | 14 | /** 15 | * @module workbox-expiration 16 | */ 17 | 18 | export {CacheExpiration, ExpirationPlugin, ExpirationPluginOptions}; 19 | -------------------------------------------------------------------------------- /packages/workbox-expiration/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig", 3 | "compilerOptions": { 4 | "composite": true, 5 | "outDir": "./", 6 | "rootDir": "./src", 7 | "tsBuildInfoFile": "./tsconfig.tsbuildinfo" 8 | }, 9 | "include": ["src/**/*.ts"], 10 | "references": [{"path": "../workbox-core/"}] 11 | } 12 | -------------------------------------------------------------------------------- /packages/workbox-google-analytics/README.md: -------------------------------------------------------------------------------- 1 | This module's documentation can be found at https://developers.google.com/web/tools/workbox/modules/workbox-google-analytics 2 | -------------------------------------------------------------------------------- /packages/workbox-google-analytics/src/_version.ts: -------------------------------------------------------------------------------- 1 | // @ts-ignore 2 | try{self['workbox:google-analytics:7.3.0']&&_()}catch(e){} -------------------------------------------------------------------------------- /packages/workbox-google-analytics/src/index.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import {initialize, GoogleAnalyticsInitializeOptions} from './initialize.js'; 10 | 11 | import './_version.js'; 12 | 13 | /** 14 | * @module workbox-google-analytics 15 | */ 16 | 17 | export {initialize, GoogleAnalyticsInitializeOptions}; 18 | -------------------------------------------------------------------------------- /packages/workbox-google-analytics/src/utils/constants.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import '../_version.js'; 10 | 11 | export const QUEUE_NAME = 'workbox-google-analytics'; 12 | export const MAX_RETENTION_TIME = 60 * 48; // Two days in minutes 13 | export const GOOGLE_ANALYTICS_HOST = 'www.google-analytics.com'; 14 | export const GTM_HOST = 'www.googletagmanager.com'; 15 | export const ANALYTICS_JS_PATH = '/analytics.js'; 16 | export const GTAG_JS_PATH = '/gtag/js'; 17 | export const GTM_JS_PATH = '/gtm.js'; 18 | export const COLLECT_DEFAULT_PATH = '/collect'; 19 | 20 | // This RegExp matches all known Measurement Protocol single-hit collect 21 | // endpoints. Most of the time the default path (/collect) is used, but 22 | // occasionally an experimental endpoint is used when testing new features, 23 | // (e.g. /r/collect or /j/collect) 24 | export const COLLECT_PATHS_REGEX = /^\/(\w+\/)?collect/; 25 | -------------------------------------------------------------------------------- /packages/workbox-google-analytics/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig", 3 | "compilerOptions": { 4 | "composite": true, 5 | "outDir": "./", 6 | "rootDir": "./src", 7 | "tsBuildInfoFile": "./tsconfig.tsbuildinfo" 8 | }, 9 | "include": ["src/**/*.ts"], 10 | "references": [ 11 | {"path": "../workbox-background-sync/"}, 12 | {"path": "../workbox-core/"}, 13 | {"path": "../workbox-routing/"}, 14 | {"path": "../workbox-strategies/"} 15 | ] 16 | } 17 | -------------------------------------------------------------------------------- /packages/workbox-navigation-preload/README.md: -------------------------------------------------------------------------------- 1 | This module's documentation can be found at https://developers.google.com/web/tools/workbox/modules/workbox-navigation-preload 2 | -------------------------------------------------------------------------------- /packages/workbox-navigation-preload/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "workbox-navigation-preload", 3 | "version": "7.3.0", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "workbox-navigation-preload", 9 | "version": "7.3.0", 10 | "license": "MIT", 11 | "dependencies": { 12 | "workbox-core": "7.3.0" 13 | } 14 | }, 15 | "node_modules/workbox-core": { 16 | "version": "7.3.0", 17 | "resolved": "https://registry.npmjs.org/workbox-core/-/workbox-core-7.3.0.tgz", 18 | "integrity": "sha512-Z+mYrErfh4t3zi7NVTvOuACB0A/jA3bgxUN3PwtAVHvfEsZxV9Iju580VEETug3zYJRc0Dmii/aixI/Uxj8fmw==", 19 | "license": "MIT" 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /packages/workbox-navigation-preload/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "workbox-navigation-preload", 3 | "version": "7.3.0", 4 | "license": "MIT", 5 | "author": "Google's Web DevRel Team and Google's Aurora Team", 6 | "description": "This library allows developers to opt-in to using Navigation Preload in their service worker.", 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/googlechrome/workbox.git" 10 | }, 11 | "bugs": "https://github.com/googlechrome/workbox/issues", 12 | "homepage": "https://github.com/GoogleChrome/workbox", 13 | "keywords": [ 14 | "workbox", 15 | "workboxjs", 16 | "service worker", 17 | "sw", 18 | "navigation" 19 | ], 20 | "workbox": { 21 | "browserNamespace": "workbox.navigationPreload", 22 | "packageType": "sw" 23 | }, 24 | "main": "index.js", 25 | "module": "index.mjs", 26 | "types": "index.d.ts", 27 | "dependencies": { 28 | "workbox-core": "7.3.0" 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /packages/workbox-navigation-preload/src/_version.ts: -------------------------------------------------------------------------------- 1 | // @ts-ignore 2 | try{self['workbox:navigation-preload:7.3.0']&&_()}catch(e){} -------------------------------------------------------------------------------- /packages/workbox-navigation-preload/src/index.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import {disable} from './disable.js'; 10 | import {enable} from './enable.js'; 11 | import {isSupported} from './isSupported.js'; 12 | import './_version.js'; 13 | 14 | // See https://github.com/GoogleChrome/workbox/issues/2946 15 | interface NavigationPreloadState { 16 | enabled?: boolean; 17 | headerValue?: string; 18 | } 19 | 20 | interface NavigationPreloadManager { 21 | disable(): Promise; 22 | enable(): Promise; 23 | getState(): Promise; 24 | setHeaderValue(value: string): Promise; 25 | } 26 | 27 | declare global { 28 | interface ServiceWorkerRegistration { 29 | readonly navigationPreload: NavigationPreloadManager; 30 | } 31 | } 32 | 33 | /** 34 | * @module workbox-navigation-preload 35 | */ 36 | 37 | export {disable, enable, isSupported}; 38 | -------------------------------------------------------------------------------- /packages/workbox-navigation-preload/src/isSupported.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import './_version.js'; 10 | 11 | // Give TypeScript the correct global. 12 | declare let self: ServiceWorkerGlobalScope; 13 | 14 | /** 15 | * @return {boolean} Whether or not the current browser supports enabling 16 | * navigation preload. 17 | * 18 | * @memberof workbox-navigation-preload 19 | */ 20 | function isSupported(): boolean { 21 | return Boolean(self.registration && self.registration.navigationPreload); 22 | } 23 | 24 | export {isSupported}; 25 | -------------------------------------------------------------------------------- /packages/workbox-navigation-preload/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig", 3 | "compilerOptions": { 4 | "outDir": "./", 5 | "rootDir": "./src", 6 | "tsBuildInfoFile": "./tsconfig.tsbuildinfo" 7 | }, 8 | "include": ["src/**/*.ts"], 9 | "references": [{"path": "../workbox-core/"}] 10 | } 11 | -------------------------------------------------------------------------------- /packages/workbox-precaching/README.md: -------------------------------------------------------------------------------- 1 | This module's documentation can be found at https://developers.google.com/web/tools/workbox/modules/workbox-precaching 2 | -------------------------------------------------------------------------------- /packages/workbox-precaching/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "workbox-precaching", 3 | "version": "7.3.0", 4 | "license": "MIT", 5 | "author": "Google's Web DevRel Team and Google's Aurora Team", 6 | "description": "This module efficiently precaches assets.", 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/googlechrome/workbox.git" 10 | }, 11 | "bugs": "https://github.com/googlechrome/workbox/issues", 12 | "homepage": "https://github.com/GoogleChrome/workbox", 13 | "keywords": [ 14 | "workbox", 15 | "workboxjs", 16 | "service worker", 17 | "sw" 18 | ], 19 | "workbox": { 20 | "browserNamespace": "workbox.precaching", 21 | "packageType": "sw" 22 | }, 23 | "main": "index.js", 24 | "module": "index.mjs", 25 | "types": "index.d.ts", 26 | "dependencies": { 27 | "workbox-core": "7.3.0", 28 | "workbox-routing": "7.3.0", 29 | "workbox-strategies": "7.3.0" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /packages/workbox-precaching/src/_version.ts: -------------------------------------------------------------------------------- 1 | // @ts-ignore 2 | try{self['workbox:precaching:7.3.0']&&_()}catch(e){} -------------------------------------------------------------------------------- /packages/workbox-precaching/src/addPlugins.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import {WorkboxPlugin} from 'workbox-core/types.js'; 10 | import {getOrCreatePrecacheController} from './utils/getOrCreatePrecacheController.js'; 11 | import './_version.js'; 12 | 13 | /** 14 | * Adds plugins to the precaching strategy. 15 | * 16 | * @param {Array} plugins 17 | * 18 | * @memberof workbox-precaching 19 | */ 20 | function addPlugins(plugins: WorkboxPlugin[]): void { 21 | const precacheController = getOrCreatePrecacheController(); 22 | precacheController.strategy.plugins.push(...plugins); 23 | } 24 | 25 | export {addPlugins}; 26 | -------------------------------------------------------------------------------- /packages/workbox-precaching/src/utils/getOrCreatePrecacheController.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import {PrecacheController} from '../PrecacheController.js'; 10 | import '../_version.js'; 11 | 12 | let precacheController: PrecacheController | undefined; 13 | 14 | /** 15 | * @return {PrecacheController} 16 | * @private 17 | */ 18 | export const getOrCreatePrecacheController = (): PrecacheController => { 19 | if (!precacheController) { 20 | precacheController = new PrecacheController(); 21 | } 22 | return precacheController; 23 | }; 24 | -------------------------------------------------------------------------------- /packages/workbox-precaching/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig", 3 | "compilerOptions": { 4 | "outDir": "./", 5 | "rootDir": "./src", 6 | "tsBuildInfoFile": "./tsconfig.tsbuildinfo" 7 | }, 8 | "include": ["src/**/*.ts"], 9 | "references": [ 10 | {"path": "../workbox-core/"}, 11 | {"path": "../workbox-routing/"}, 12 | {"path": "../workbox-strategies/"} 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /packages/workbox-range-requests/README.md: -------------------------------------------------------------------------------- 1 | This module's documentation can be found at https://developers.google.com/web/tools/workbox/modules/workbox-range-requests 2 | -------------------------------------------------------------------------------- /packages/workbox-range-requests/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "workbox-range-requests", 3 | "version": "7.3.0", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "workbox-range-requests", 9 | "version": "7.3.0", 10 | "license": "MIT", 11 | "dependencies": { 12 | "workbox-core": "7.3.0" 13 | } 14 | }, 15 | "node_modules/workbox-core": { 16 | "version": "7.3.0", 17 | "resolved": "https://registry.npmjs.org/workbox-core/-/workbox-core-7.3.0.tgz", 18 | "integrity": "sha512-Z+mYrErfh4t3zi7NVTvOuACB0A/jA3bgxUN3PwtAVHvfEsZxV9Iju580VEETug3zYJRc0Dmii/aixI/Uxj8fmw==", 19 | "license": "MIT" 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /packages/workbox-range-requests/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "workbox-range-requests", 3 | "version": "7.3.0", 4 | "license": "MIT", 5 | "author": "Google's Web DevRel Team and Google's Aurora Team", 6 | "description": "This library creates a new Response, given a source Response and a Range header value.", 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/googlechrome/workbox.git" 10 | }, 11 | "bugs": "https://github.com/googlechrome/workbox/issues", 12 | "homepage": "https://github.com/GoogleChrome/workbox", 13 | "keywords": [ 14 | "workbox", 15 | "workboxjs", 16 | "service worker", 17 | "sw", 18 | "caching", 19 | "cache", 20 | "range", 21 | "media", 22 | "workbox-plugin" 23 | ], 24 | "workbox": { 25 | "browserNamespace": "workbox.rangeRequests", 26 | "packageType": "sw" 27 | }, 28 | "main": "index.js", 29 | "module": "index.mjs", 30 | "types": "index.d.ts", 31 | "dependencies": { 32 | "workbox-core": "7.3.0" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /packages/workbox-range-requests/src/_version.ts: -------------------------------------------------------------------------------- 1 | // @ts-ignore 2 | try{self['workbox:range-requests:7.3.0']&&_()}catch(e){} -------------------------------------------------------------------------------- /packages/workbox-range-requests/src/index.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import {createPartialResponse} from './createPartialResponse.js'; 10 | import {RangeRequestsPlugin} from './RangeRequestsPlugin.js'; 11 | import './_version.js'; 12 | 13 | /** 14 | * @module workbox-range-requests 15 | */ 16 | 17 | export {createPartialResponse, RangeRequestsPlugin}; 18 | -------------------------------------------------------------------------------- /packages/workbox-range-requests/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig", 3 | "compilerOptions": { 4 | "outDir": "./", 5 | "rootDir": "./src", 6 | "tsBuildInfoFile": "./tsconfig.tsbuildinfo" 7 | }, 8 | "include": ["src/**/*.ts"], 9 | "references": [{"path": "../workbox-core/"}] 10 | } 11 | -------------------------------------------------------------------------------- /packages/workbox-recipes/README.md: -------------------------------------------------------------------------------- 1 | This module's documentation can be found at https://developers.google.com/web/tools/workbox/modules/workbox-recipes 2 | -------------------------------------------------------------------------------- /packages/workbox-recipes/src/_version.ts: -------------------------------------------------------------------------------- 1 | // @ts-ignore 2 | try{self['workbox:recipes:7.3.0']&&_()}catch(e){} -------------------------------------------------------------------------------- /packages/workbox-recipes/src/warmStrategyCache.ts: -------------------------------------------------------------------------------- 1 | import {Strategy} from 'workbox-strategies/Strategy.js'; 2 | 3 | import './_version.js'; 4 | 5 | export interface WarmStrategyCacheOptions { 6 | urls: Array; 7 | strategy: Strategy; 8 | } 9 | 10 | // Give TypeScript the correct global. 11 | declare let self: ServiceWorkerGlobalScope; 12 | 13 | /** 14 | * @memberof workbox-recipes 15 | 16 | * @param {Object} options 17 | * @param {string[]} options.urls Paths to warm the strategy's cache with 18 | * @param {Strategy} options.strategy Strategy to use 19 | */ 20 | function warmStrategyCache(options: WarmStrategyCacheOptions): void { 21 | self.addEventListener('install', (event) => { 22 | const done = options.urls.map( 23 | (path) => 24 | options.strategy.handleAll({ 25 | event, 26 | request: new Request(path), 27 | })[1], 28 | ); 29 | 30 | event.waitUntil(Promise.all(done)); 31 | }); 32 | } 33 | 34 | export {warmStrategyCache}; 35 | -------------------------------------------------------------------------------- /packages/workbox-recipes/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig", 3 | "compilerOptions": { 4 | "outDir": "./", 5 | "rootDir": "./src", 6 | "tsBuildInfoFile": "./tsconfig.tsbuildinfo" 7 | }, 8 | "include": ["src/**/*.ts"], 9 | "references": [ 10 | {"path": "../workbox-core/"}, 11 | {"path": "../workbox-routing/"}, 12 | {"path": "../workbox-strategies/"}, 13 | {"path": "../workbox-cacheable-response/"}, 14 | {"path": "../workbox-expiration/"}, 15 | {"path": "../workbox-precaching/"} 16 | ] 17 | } 18 | -------------------------------------------------------------------------------- /packages/workbox-routing/README.md: -------------------------------------------------------------------------------- 1 | This module's documentation can be found at https://developers.google.com/web/tools/workbox/modules/workbox-routing 2 | -------------------------------------------------------------------------------- /packages/workbox-routing/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "workbox-routing", 3 | "version": "7.3.0", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "workbox-routing", 9 | "version": "7.3.0", 10 | "license": "MIT", 11 | "dependencies": { 12 | "workbox-core": "7.3.0" 13 | } 14 | }, 15 | "node_modules/workbox-core": { 16 | "version": "7.3.0", 17 | "resolved": "https://registry.npmjs.org/workbox-core/-/workbox-core-7.3.0.tgz", 18 | "integrity": "sha512-Z+mYrErfh4t3zi7NVTvOuACB0A/jA3bgxUN3PwtAVHvfEsZxV9Iju580VEETug3zYJRc0Dmii/aixI/Uxj8fmw==", 19 | "license": "MIT" 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /packages/workbox-routing/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "workbox-routing", 3 | "version": "7.3.0", 4 | "license": "MIT", 5 | "author": "Google's Web DevRel Team and Google's Aurora Team", 6 | "description": "A service worker helper library to route request URLs to handlers.", 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/googlechrome/workbox.git" 10 | }, 11 | "bugs": "https://github.com/googlechrome/workbox/issues", 12 | "homepage": "https://github.com/GoogleChrome/workbox", 13 | "keywords": [ 14 | "workbox", 15 | "workboxjs", 16 | "service worker", 17 | "sw", 18 | "router", 19 | "routing" 20 | ], 21 | "workbox": { 22 | "browserNamespace": "workbox.routing", 23 | "packageType": "sw" 24 | }, 25 | "main": "index.js", 26 | "module": "index.mjs", 27 | "types": "index.d.ts", 28 | "dependencies": { 29 | "workbox-core": "7.3.0" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /packages/workbox-routing/src/_version.ts: -------------------------------------------------------------------------------- 1 | // @ts-ignore 2 | try{self['workbox:routing:7.3.0']&&_()}catch(e){} -------------------------------------------------------------------------------- /packages/workbox-routing/src/index.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import { 10 | NavigationRoute, 11 | NavigationRouteMatchOptions, 12 | } from './NavigationRoute.js'; 13 | import {RegExpRoute} from './RegExpRoute.js'; 14 | import {registerRoute} from './registerRoute.js'; 15 | import {Route} from './Route.js'; 16 | import {Router} from './Router.js'; 17 | import {setCatchHandler} from './setCatchHandler.js'; 18 | import {setDefaultHandler} from './setDefaultHandler.js'; 19 | 20 | import './_version.js'; 21 | 22 | /** 23 | * @module workbox-routing 24 | */ 25 | 26 | export { 27 | NavigationRoute, 28 | RegExpRoute, 29 | registerRoute, 30 | Route, 31 | Router, 32 | setCatchHandler, 33 | setDefaultHandler, 34 | NavigationRouteMatchOptions, 35 | }; 36 | -------------------------------------------------------------------------------- /packages/workbox-routing/src/setCatchHandler.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import {RouteHandler} from 'workbox-core/types.js'; 10 | 11 | import {getOrCreateDefaultRouter} from './utils/getOrCreateDefaultRouter.js'; 12 | 13 | import './_version.js'; 14 | 15 | /** 16 | * If a Route throws an error while handling a request, this `handler` 17 | * will be called and given a chance to provide a response. 18 | * 19 | * @param {workbox-routing~handlerCallback} handler A callback 20 | * function that returns a Promise resulting in a Response. 21 | * 22 | * @memberof workbox-routing 23 | */ 24 | function setCatchHandler(handler: RouteHandler): void { 25 | const defaultRouter = getOrCreateDefaultRouter(); 26 | defaultRouter.setCatchHandler(handler); 27 | } 28 | 29 | export {setCatchHandler}; 30 | -------------------------------------------------------------------------------- /packages/workbox-routing/src/setDefaultHandler.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import {RouteHandler} from 'workbox-core/types.js'; 10 | 11 | import {getOrCreateDefaultRouter} from './utils/getOrCreateDefaultRouter.js'; 12 | 13 | import './_version.js'; 14 | 15 | /** 16 | * Define a default `handler` that's called when no routes explicitly 17 | * match the incoming request. 18 | * 19 | * Without a default handler, unmatched requests will go against the 20 | * network as if there were no service worker present. 21 | * 22 | * @param {workbox-routing~handlerCallback} handler A callback 23 | * function that returns a Promise resulting in a Response. 24 | * 25 | * @memberof workbox-routing 26 | */ 27 | function setDefaultHandler(handler: RouteHandler): void { 28 | const defaultRouter = getOrCreateDefaultRouter(); 29 | defaultRouter.setDefaultHandler(handler); 30 | } 31 | 32 | export {setDefaultHandler}; 33 | -------------------------------------------------------------------------------- /packages/workbox-routing/src/utils/constants.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import '../_version.js'; 10 | 11 | export type HTTPMethod = 'DELETE' | 'GET' | 'HEAD' | 'PATCH' | 'POST' | 'PUT'; 12 | 13 | /** 14 | * The default HTTP method, 'GET', used when there's no specific method 15 | * configured for a route. 16 | * 17 | * @type {string} 18 | * 19 | * @private 20 | */ 21 | export const defaultMethod: HTTPMethod = 'GET'; 22 | 23 | /** 24 | * The list of valid HTTP methods associated with requests that could be routed. 25 | * 26 | * @type {Array} 27 | * 28 | * @private 29 | */ 30 | export const validMethods: HTTPMethod[] = [ 31 | 'DELETE', 32 | 'GET', 33 | 'HEAD', 34 | 'PATCH', 35 | 'POST', 36 | 'PUT', 37 | ]; 38 | -------------------------------------------------------------------------------- /packages/workbox-routing/src/utils/getOrCreateDefaultRouter.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import {Router} from '../Router.js'; 10 | import '../_version.js'; 11 | 12 | let defaultRouter: Router; 13 | 14 | /** 15 | * Creates a new, singleton Router instance if one does not exist. If one 16 | * does already exist, that instance is returned. 17 | * 18 | * @private 19 | * @return {Router} 20 | */ 21 | export const getOrCreateDefaultRouter = (): Router => { 22 | if (!defaultRouter) { 23 | defaultRouter = new Router(); 24 | 25 | // The helpers that use the default Router assume these listeners exist. 26 | defaultRouter.addFetchListener(); 27 | defaultRouter.addCacheListener(); 28 | } 29 | return defaultRouter; 30 | }; 31 | -------------------------------------------------------------------------------- /packages/workbox-routing/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig", 3 | "compilerOptions": { 4 | "composite": true, 5 | "outDir": "./", 6 | "rootDir": "./src", 7 | "tsBuildInfoFile": "./tsconfig.tsbuildinfo" 8 | }, 9 | "include": ["src/**/*.ts"], 10 | "references": [{"path": "../workbox-core/"}] 11 | } 12 | -------------------------------------------------------------------------------- /packages/workbox-strategies/README.md: -------------------------------------------------------------------------------- 1 | This module's documentation can be found at https://developers.google.com/web/tools/workbox/modules/workbox-strategies 2 | -------------------------------------------------------------------------------- /packages/workbox-strategies/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "workbox-strategies", 3 | "version": "7.3.0", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "workbox-strategies", 9 | "version": "7.3.0", 10 | "license": "MIT", 11 | "dependencies": { 12 | "workbox-core": "7.3.0" 13 | } 14 | }, 15 | "node_modules/workbox-core": { 16 | "version": "7.3.0", 17 | "resolved": "https://registry.npmjs.org/workbox-core/-/workbox-core-7.3.0.tgz", 18 | "integrity": "sha512-Z+mYrErfh4t3zi7NVTvOuACB0A/jA3bgxUN3PwtAVHvfEsZxV9Iju580VEETug3zYJRc0Dmii/aixI/Uxj8fmw==", 19 | "license": "MIT" 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /packages/workbox-strategies/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "workbox-strategies", 3 | "version": "7.3.0", 4 | "license": "MIT", 5 | "author": "Google's Web DevRel Team and Google's Aurora Team", 6 | "description": "A service worker helper library implementing common caching strategies.", 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/googlechrome/workbox.git" 10 | }, 11 | "bugs": "https://github.com/googlechrome/workbox/issues", 12 | "homepage": "https://github.com/GoogleChrome/workbox", 13 | "keywords": [ 14 | "workbox", 15 | "workboxjs", 16 | "service worker", 17 | "sw", 18 | "router", 19 | "routing" 20 | ], 21 | "workbox": { 22 | "browserNamespace": "workbox.strategies", 23 | "packageType": "sw" 24 | }, 25 | "main": "index.js", 26 | "module": "index.mjs", 27 | "types": "index.d.ts", 28 | "dependencies": { 29 | "workbox-core": "7.3.0" 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /packages/workbox-strategies/src/_version.ts: -------------------------------------------------------------------------------- 1 | // @ts-ignore 2 | try{self['workbox:strategies:7.3.0']&&_()}catch(e){} -------------------------------------------------------------------------------- /packages/workbox-strategies/src/plugins/cacheOkAndOpaquePlugin.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import {WorkboxPlugin} from 'workbox-core/types.js'; 10 | import '../_version.js'; 11 | 12 | export const cacheOkAndOpaquePlugin: WorkboxPlugin = { 13 | /** 14 | * Returns a valid response (to allow caching) if the status is 200 (OK) or 15 | * 0 (opaque). 16 | * 17 | * @param {Object} options 18 | * @param {Response} options.response 19 | * @return {Response|null} 20 | * 21 | * @private 22 | */ 23 | cacheWillUpdate: async ({response}) => { 24 | if (response.status === 200 || response.status === 0) { 25 | return response; 26 | } 27 | return null; 28 | }, 29 | }; 30 | -------------------------------------------------------------------------------- /packages/workbox-strategies/src/utils/messages.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import {logger} from 'workbox-core/_private/logger.js'; 10 | import {getFriendlyURL} from 'workbox-core/_private/getFriendlyURL.js'; 11 | import '../_version.js'; 12 | 13 | export const messages = { 14 | strategyStart: (strategyName: string, request: Request): string => 15 | `Using ${strategyName} to respond to '${getFriendlyURL(request.url)}'`, 16 | printFinalResponse: (response?: Response): void => { 17 | if (response) { 18 | logger.groupCollapsed(`View the final response here.`); 19 | logger.log(response || '[No response returned]'); 20 | logger.groupEnd(); 21 | } 22 | }, 23 | }; 24 | -------------------------------------------------------------------------------- /packages/workbox-strategies/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig", 3 | "compilerOptions": { 4 | "composite": true, 5 | "outDir": "./", 6 | "rootDir": "./src", 7 | "tsBuildInfoFile": "./tsconfig.tsbuildinfo" 8 | }, 9 | "include": ["src/**/*.ts"], 10 | "references": [{"path": "../workbox-core/"}] 11 | } 12 | -------------------------------------------------------------------------------- /packages/workbox-streams/README.md: -------------------------------------------------------------------------------- 1 | This module's documentation can be found at https://developers.google.com/web/tools/workbox/reference-docs/latest/module-workbox-streams 2 | -------------------------------------------------------------------------------- /packages/workbox-streams/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "workbox-streams", 3 | "version": "7.3.0", 4 | "license": "MIT", 5 | "author": "Google's Web DevRel Team and Google's Aurora Team", 6 | "description": "A library that makes it easier to work with Streams in the browser.", 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/googlechrome/workbox.git" 10 | }, 11 | "bugs": "https://github.com/googlechrome/workbox/issues", 12 | "homepage": "https://github.com/GoogleChrome/workbox", 13 | "keywords": [ 14 | "workbox", 15 | "workboxjs", 16 | "service worker", 17 | "sw", 18 | "streams", 19 | "readablestream" 20 | ], 21 | "workbox": { 22 | "browserNamespace": "workbox.streams", 23 | "packageType": "sw" 24 | }, 25 | "main": "index.js", 26 | "module": "index.mjs", 27 | "types": "index.d.ts", 28 | "dependencies": { 29 | "workbox-core": "7.3.0", 30 | "workbox-routing": "7.3.0" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /packages/workbox-streams/src/_types.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import './_version.js'; 10 | 11 | export type StreamSource = Response | ReadableStream | BodyInit; 12 | 13 | // * * * IMPORTANT! * * * 14 | // ------------------------------------------------------------------------- // 15 | // jdsoc type definitions cannot be declared above TypeScript definitions or 16 | // they'll be stripped from the built `.js` files, and they'll only be in the 17 | // `d.ts` files, which aren't read by the jsdoc generator. As a result we 18 | // have to put declare them below. 19 | 20 | /** 21 | * @typedef {Response|ReadableStream|BodyInit} StreamSource 22 | * @memberof workbox-streams 23 | */ 24 | -------------------------------------------------------------------------------- /packages/workbox-streams/src/_version.ts: -------------------------------------------------------------------------------- 1 | // @ts-ignore 2 | try{self['workbox:streams:7.3.0']&&_()}catch(e){} -------------------------------------------------------------------------------- /packages/workbox-streams/src/index.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import {concatenate} from './concatenate.js'; 10 | import {concatenateToResponse} from './concatenateToResponse.js'; 11 | import {isSupported} from './isSupported.js'; 12 | import {strategy, StreamsHandlerCallback} from './strategy.js'; 13 | 14 | import './_version.js'; 15 | 16 | /** 17 | * @module workbox-streams 18 | */ 19 | 20 | export { 21 | concatenate, 22 | concatenateToResponse, 23 | isSupported, 24 | strategy, 25 | StreamsHandlerCallback, 26 | }; 27 | 28 | export * from './_types.js'; 29 | -------------------------------------------------------------------------------- /packages/workbox-streams/src/isSupported.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import {canConstructReadableStream} from 'workbox-core/_private/canConstructReadableStream.js'; 10 | import './_version.js'; 11 | 12 | /** 13 | * This is a utility method that determines whether the current browser supports 14 | * the features required to create streamed responses. Currently, it checks if 15 | * [`ReadableStream`](https://developer.mozilla.org/en-US/docs/Web/API/ReadableStream/ReadableStream) 16 | * can be created. 17 | * 18 | * @return {boolean} `true`, if the current browser meets the requirements for 19 | * streaming responses, and `false` otherwise. 20 | * 21 | * @memberof workbox-streams 22 | */ 23 | function isSupported(): boolean { 24 | return canConstructReadableStream(); 25 | } 26 | 27 | export {isSupported}; 28 | -------------------------------------------------------------------------------- /packages/workbox-streams/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig", 3 | "compilerOptions": { 4 | "outDir": "./", 5 | "rootDir": "./src", 6 | "tsBuildInfoFile": "./tsconfig.tsbuildinfo" 7 | }, 8 | "include": ["src/**/*.ts"], 9 | "references": [{"path": "../workbox-core/"}] 10 | } 11 | -------------------------------------------------------------------------------- /packages/workbox-sw/README.md: -------------------------------------------------------------------------------- 1 | This module's documentation can be found at https://developers.google.com/web/tools/workbox/modules/workbox-sw 2 | -------------------------------------------------------------------------------- /packages/workbox-sw/_types.mjs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import './_version.mjs'; 10 | 11 | /** 12 | * A `ModulePathCallback` function can be used to modify the modify the where 13 | * Workbox modules are loaded. 14 | * 15 | * @callback ~ModulePathCallback 16 | * @param {string} moduleName The name of the module to load (i.e. 17 | * 'workbox-core', 'workbox-precaching' etc.). 18 | * @param {boolean} debug When true, `dev` builds should be loaded, otherwise 19 | * load `prod` builds. 20 | * @return {string} This callback should return a path of module. This will 21 | * be passed to `importScripts()`. 22 | * 23 | * @memberof workbox 24 | */ 25 | -------------------------------------------------------------------------------- /packages/workbox-sw/_version.mjs: -------------------------------------------------------------------------------- 1 | try{self['workbox:sw:7.3.0']&&_()}catch(e){}// eslint-disable-line -------------------------------------------------------------------------------- /packages/workbox-sw/index.mjs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import {WorkboxSW} from './controllers/WorkboxSW.mjs'; 10 | import './_version.mjs'; 11 | 12 | /** 13 | * @namespace workbox 14 | */ 15 | 16 | // Don't export anything, just expose a global. 17 | self.workbox = new WorkboxSW(); 18 | -------------------------------------------------------------------------------- /packages/workbox-sw/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "workbox-sw", 3 | "version": "7.3.0", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "workbox-sw", 9 | "version": "7.3.0", 10 | "license": "MIT" 11 | } 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /packages/workbox-sw/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "workbox-sw", 3 | "version": "7.3.0", 4 | "license": "MIT", 5 | "author": "Google's Web DevRel Team and Google's Aurora Team", 6 | "description": "This module makes it easy to get started with the Workbox service worker libraries.", 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/googlechrome/workbox.git" 10 | }, 11 | "bugs": "https://github.com/googlechrome/workbox/issues", 12 | "homepage": "https://github.com/GoogleChrome/workbox", 13 | "keywords": [ 14 | "workbox", 15 | "workboxjs", 16 | "service worker", 17 | "sw" 18 | ], 19 | "workbox": { 20 | "browserNamespace": "workbox", 21 | "packageType": "sw", 22 | "prodOnly": true 23 | }, 24 | "main": "build/workbox-sw.js", 25 | "module": "index.mjs" 26 | } 27 | -------------------------------------------------------------------------------- /packages/workbox-webpack-plugin/README.md: -------------------------------------------------------------------------------- 1 | This module's documentation can be found at https://developer.chrome.com/docs/workbox/modules/workbox-webpack-plugin/ 2 | -------------------------------------------------------------------------------- /packages/workbox-webpack-plugin/src/index.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import {GenerateSW, GenerateSWConfig} from './generate-sw'; 10 | import {InjectManifest} from './inject-manifest'; 11 | 12 | /** 13 | * @module workbox-webpack-plugin 14 | */ 15 | export {GenerateSW, GenerateSWConfig, InjectManifest}; 16 | 17 | // TODO: remove this in v7. 18 | // See https://github.com/GoogleChrome/workbox/issues/3033 19 | export default {GenerateSW, InjectManifest}; 20 | -------------------------------------------------------------------------------- /packages/workbox-webpack-plugin/src/lib/get-asset-hash.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import crypto from 'crypto'; 10 | import type {Asset} from 'webpack'; 11 | 12 | /** 13 | * @param {Asset} asset 14 | * @return {string} The MD5 hash of the asset's source. 15 | * 16 | * @private 17 | */ 18 | export function getAssetHash(asset: Asset): string | null { 19 | // If webpack has the asset marked as immutable, then we don't need to 20 | // use an out-of-band revision for it. 21 | // See https://github.com/webpack/webpack/issues/9038 22 | if (asset.info && asset.info.immutable) { 23 | return null; 24 | } 25 | 26 | return crypto 27 | .createHash('md5') 28 | .update(Buffer.from(asset.source.source() as Buffer)) 29 | .digest('hex'); 30 | } 31 | -------------------------------------------------------------------------------- /packages/workbox-webpack-plugin/src/lib/relative-to-output-path.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import upath from 'upath'; 10 | import type {Compilation} from 'webpack'; 11 | 12 | /** 13 | * @param {Object} compilation The webpack compilation. 14 | * @param {string} swDest The original swDest value. 15 | * 16 | * @return {string} If swDest was not absolute, the returns swDest as-is. 17 | * Otherwise, returns swDest relative to the compilation's output path. 18 | * 19 | * @private 20 | */ 21 | export function relativeToOutputPath( 22 | compilation: Compilation, 23 | swDest: string, 24 | ): string { 25 | // See https://github.com/jantimon/html-webpack-plugin/pull/266/files#diff-168726dbe96b3ce427e7fedce31bb0bcR38 26 | if (upath.resolve(swDest) === upath.normalize(swDest)) { 27 | return upath.relative(compilation.options.output.path!, swDest); 28 | } 29 | 30 | // Otherwise, return swDest as-is. 31 | return swDest; 32 | } 33 | -------------------------------------------------------------------------------- /packages/workbox-webpack-plugin/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig", 3 | "compilerOptions": { 4 | "esModuleInterop": true, 5 | "module": "CommonJS", 6 | "outDir": "./build", 7 | "resolveJsonModule": true, 8 | "rootDir": "./src", 9 | "target": "ES2018", 10 | "tsBuildInfoFile": "./tsconfig.tsbuildinfo" 11 | }, 12 | "include": ["src/**/*.ts"], 13 | "references": [{"path": "../workbox-build/"}] 14 | } 15 | -------------------------------------------------------------------------------- /packages/workbox-window/README.md: -------------------------------------------------------------------------------- 1 | This module's documentation can be found at https://developers.google.com/web/tools/workbox/modules/workbox-window 2 | -------------------------------------------------------------------------------- /packages/workbox-window/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "workbox-window", 3 | "version": "7.3.0", 4 | "license": "MIT", 5 | "author": "Google's Web DevRel Team and Google's Aurora Team", 6 | "description": "Simplifies communications with Workbox packages running in the service worker", 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/googlechrome/workbox.git" 10 | }, 11 | "bugs": "https://github.com/googlechrome/workbox/issues", 12 | "homepage": "https://github.com/GoogleChrome/workbox", 13 | "keywords": [ 14 | "workbox", 15 | "workboxjs", 16 | "service worker", 17 | "sw", 18 | "window", 19 | "message", 20 | "postMessage" 21 | ], 22 | "workbox": { 23 | "packageType": "window", 24 | "primaryBuild": "build/workbox-window.prod.mjs" 25 | }, 26 | "main": "build/workbox-window.prod.umd.js", 27 | "module": "build/workbox-window.prod.es5.mjs", 28 | "types": "index.d.ts", 29 | "dependencies": { 30 | "@types/trusted-types": "^2.0.2", 31 | "workbox-core": "7.3.0" 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /packages/workbox-window/src/_version.ts: -------------------------------------------------------------------------------- 1 | // @ts-ignore 2 | try{self['workbox:window:7.3.0']&&_()}catch(e){} -------------------------------------------------------------------------------- /packages/workbox-window/src/index.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import {messageSW} from './messageSW.js'; 10 | import {Workbox} from './Workbox.js'; 11 | 12 | import './_version.js'; 13 | 14 | /** 15 | * @module workbox-window 16 | */ 17 | export {messageSW, Workbox}; 18 | 19 | // See https://github.com/GoogleChrome/workbox/issues/2770 20 | export * from './utils/WorkboxEvent.js'; 21 | -------------------------------------------------------------------------------- /packages/workbox-window/src/utils/urlsMatch.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import '../_version.js'; 10 | 11 | /** 12 | * Returns true if two URLs have the same `.href` property. The URLS can be 13 | * relative, and if they are the current location href is used to resolve URLs. 14 | * 15 | * @private 16 | * @param {string} url1 17 | * @param {string} url2 18 | * @return {boolean} 19 | */ 20 | export function urlsMatch(url1: string, url2: string): boolean { 21 | const {href} = location; 22 | return new URL(url1, href).href === new URL(url2, href).href; 23 | } 24 | -------------------------------------------------------------------------------- /packages/workbox-window/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig", 3 | "compilerOptions": { 4 | "lib": ["es2017", "dom"], 5 | "outDir": "./", 6 | "rootDir": "./src", 7 | "tsBuildInfoFile": "./tsconfig.tsbuildinfo" 8 | }, 9 | "include": ["src/**/*.ts"], 10 | "references": [ 11 | { 12 | "path": "../workbox-core/" 13 | } 14 | ] 15 | } 16 | -------------------------------------------------------------------------------- /prettier.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | arrowParens: 'always', 3 | bracketSpacing: false, 4 | printWidth: 80, 5 | quoteProps: 'consistent', 6 | semi: true, 7 | singleQuote: true, 8 | tabWidth: 2, 9 | trailingComma: 'all', 10 | }; 11 | -------------------------------------------------------------------------------- /test/workbox-background-sync/static/basic-example/example.txt: -------------------------------------------------------------------------------- 1 | example.txt -------------------------------------------------------------------------------- /test/workbox-background-sync/static/basic-example/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

You need to manually register sw.js

5 | 6 | 7 | -------------------------------------------------------------------------------- /test/workbox-broadcast-update/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

You need to manually register sw.js

5 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /test/workbox-build/node/lib/escape-regexp.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | const expect = require('chai').expect; 10 | const { 11 | escapeRegExp, 12 | } = require('../../../../packages/workbox-build/build/lib/escape-regexp'); 13 | 14 | describe(`[workbox-build] lib/copy-workbox-libraries.js`, function () { 15 | const expectedValues = new Map([ 16 | ['abcd', 'abcd'], 17 | ['\\abc()d', '\\\\abc\\(\\)d'], 18 | ['$?.js', '\\$\\?\\.js'], 19 | ['.*+?^${}()|[]\\', '\\.\\*\\+\\?\\^\\$\\{\\}\\(\\)\\|\\[\\]\\\\'], 20 | ]); 21 | 22 | for (const [original, escaped] of expectedValues) { 23 | it(`should perform the expected escaping: ${original} => ${escaped}`, async function () { 24 | expect(escapeRegExp(original)).to.eql(escaped); 25 | }); 26 | } 27 | }); 28 | -------------------------------------------------------------------------------- /test/workbox-build/node/lib/get-string-hash.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | const expect = require('chai').expect; 10 | 11 | const { 12 | getStringHash, 13 | } = require('../../../../packages/workbox-build/build/lib/get-string-hash'); 14 | 15 | describe(`[workbox-build] lib/get-string-hash.js`, function () { 16 | it(`should return the expected hashes`, function () { 17 | const stringsToHashes = new Map([ 18 | ['abc', '900150983cd24fb0d6963f7d28e17f72'], 19 | ['xyz', 'd16fb36f0911f878998c136191af705e'], 20 | ]); 21 | 22 | for (const [string, hash] of stringsToHashes) { 23 | expect(getStringHash(string)).to.eql(hash); 24 | } 25 | }); 26 | }); 27 | -------------------------------------------------------------------------------- /test/workbox-build/static/example-project-1/.hidden-directory/hello.html: -------------------------------------------------------------------------------- 1 |

.hidden-directory/hello

2 | -------------------------------------------------------------------------------- /test/workbox-build/static/example-project-1/.hidden-directory/hello.js: -------------------------------------------------------------------------------- 1 | console.log('.hidden-directory/hello.js'); 2 | -------------------------------------------------------------------------------- /test/workbox-build/static/example-project-1/images/example-jpeg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GoogleChrome/workbox/e26d8d7507f9412ba029922f3d9920e68710f2cf/test/workbox-build/static/example-project-1/images/example-jpeg.jpg -------------------------------------------------------------------------------- /test/workbox-build/static/example-project-1/images/web-fundamentals-icon192x192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GoogleChrome/workbox/e26d8d7507f9412ba029922f3d9920e68710f2cf/test/workbox-build/static/example-project-1/images/web-fundamentals-icon192x192.png -------------------------------------------------------------------------------- /test/workbox-build/static/example-project-1/page-1.html: -------------------------------------------------------------------------------- 1 |

Page 1

2 | -------------------------------------------------------------------------------- /test/workbox-build/static/example-project-1/page-2.html: -------------------------------------------------------------------------------- 1 |

Page 2

2 | -------------------------------------------------------------------------------- /test/workbox-build/static/example-project-1/styles/stylesheet-1.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: red; 3 | } 4 | -------------------------------------------------------------------------------- /test/workbox-build/static/example-project-1/styles/stylesheet-2.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: blue; 3 | } 4 | -------------------------------------------------------------------------------- /test/workbox-build/static/example-project-1/webpackEntry.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | -------------------------------------------------------------------------------- /test/workbox-build/static/sw-injections/bad-multiple-injection.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | // Multiple entries. 10 | workbox.precaching.precacheAndRoute(self.__WB_MANIFEST); 11 | workbox.precaching.precacheAndRoute(self.__WB_MANIFEST); 12 | -------------------------------------------------------------------------------- /test/workbox-build/static/sw-injections/bad-no-injection.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | // This file has no injection point....should throw in the tests. 10 | -------------------------------------------------------------------------------- /test/workbox-build/static/sw-injections/basic.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | workbox.precaching.precacheAndRoute(self.__WB_MANIFEST); 10 | -------------------------------------------------------------------------------- /test/workbox-build/static/sw-injections/custom-injection-point.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | workbox.precaching.precacheAndRoute(self.__custom_injection_point); 10 | -------------------------------------------------------------------------------- /test/workbox-build/static/sw-injections/multiple-calls.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | importScripts('./sample-import.js'); 10 | 11 | const precache = (input) => { 12 | // no-op 13 | }; 14 | 15 | precache([]); 16 | 17 | // The automatic injection will happen here: 18 | workbox.precaching.precacheAndRoute(self.__WB_MANIFEST); 19 | 20 | // Then, call precache again: 21 | workbox.precaching.precacheAndRoute([ 22 | '/extra-assets/example.1234.css', 23 | '/extra-assets/example-2.1234.js', 24 | ]); 25 | -------------------------------------------------------------------------------- /test/workbox-build/static/sw-injections/precache-and-route-options.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | workbox.precaching.precacheAndRoute(self.__WB_MANIFEST, { 10 | cleanURLs: true, 11 | }); 12 | -------------------------------------------------------------------------------- /test/workbox-build/static/sw-injections/sample-import.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | -------------------------------------------------------------------------------- /test/workbox-cacheable-response/static/cacheable-response-plugin/example-1.txt: -------------------------------------------------------------------------------- 1 | example-1.txt 2 | -------------------------------------------------------------------------------- /test/workbox-cacheable-response/static/cacheable-response-plugin/sw.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | importScripts('/__WORKBOX/buildFile/workbox-core'); 10 | importScripts('/__WORKBOX/buildFile/workbox-cacheable-response'); 11 | importScripts('/__WORKBOX/buildFile/workbox-routing'); 12 | importScripts('/__WORKBOX/buildFile/workbox-strategies'); 13 | importScripts('/infra/testing/comlink/sw-interface.js'); 14 | 15 | workbox.routing.registerRoute( 16 | /.*.txt/, 17 | new workbox.strategies.CacheFirst({ 18 | cacheName: 'cacheable-response-cache', 19 | plugins: [ 20 | new workbox.cacheableResponse.CacheableResponsePlugin({ 21 | statuses: [0, 200], 22 | }), 23 | ], 24 | }), 25 | ); 26 | 27 | self.addEventListener('install', (event) => 28 | event.waitUntil(self.skipWaiting()), 29 | ); 30 | self.addEventListener('activate', (event) => 31 | event.waitUntil(self.clients.claim()), 32 | ); 33 | -------------------------------------------------------------------------------- /test/workbox-cli/node/lib/help-text.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | const expect = require('chai').expect; 10 | 11 | describe(`[workbox-cli] lib/help-text.js`, function () { 12 | it(`should be a string`, function () { 13 | const { 14 | helpText, 15 | } = require('../../../../packages/workbox-cli/build/lib/help-text'); 16 | expect(helpText).to.be.a('string'); 17 | }); 18 | }); 19 | -------------------------------------------------------------------------------- /test/workbox-cli/node/lib/questions/ask-sw-src.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | const expect = require('chai').expect; 10 | const proxyquire = require('proxyquire'); 11 | 12 | const MODULE_PATH = 13 | '../../../../../packages/workbox-cli/build/lib/questions/ask-sw-src'; 14 | // This is the hardcoded name of the question that's passed to inquirer. 15 | // It's used as the key to read the response from the answer. 16 | const QUESTION_NAME = 'swSrc'; 17 | 18 | describe(`[workbox-cli] lib/questions/ask-sw-src.js`, function () { 19 | it(`should resolve with a valid answer to the question`, async function () { 20 | const expectedAnswer = 'expected answer'; 21 | const {askSWSrc} = proxyquire(MODULE_PATH, { 22 | inquirer: { 23 | prompt: () => Promise.resolve({[QUESTION_NAME]: expectedAnswer}), 24 | }, 25 | }); 26 | 27 | const answer = await askSWSrc(); 28 | expect(answer).to.eql(expectedAnswer); 29 | }); 30 | }); 31 | -------------------------------------------------------------------------------- /test/workbox-core/static/core-in-browser/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

You need to manually register sw.js

5 | 6 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /test/workbox-core/sw/_private/test-timeout.mjs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import {timeout} from 'workbox-core/_private/timeout.mjs'; 10 | 11 | describe(`timeout()`, function () { 12 | const sandbox = sinon.createSandbox(); 13 | 14 | beforeEach(async function () { 15 | sandbox.restore(); 16 | }); 17 | 18 | afterEach(function () { 19 | sandbox.restore(); 20 | }); 21 | 22 | it(`should return a promise that resolves after the passed number of milliseconds`, function (done) { 23 | const clock = sandbox.useFakeTimers(); 24 | const startTime = performance.now(); 25 | 26 | timeout(123).then(() => { 27 | expect(performance.now() - startTime).to.equal(123); 28 | clock.tick(456); 29 | }); 30 | 31 | timeout(456).then(() => { 32 | expect(performance.now() - startTime).to.equal(123 + 456); 33 | done(); 34 | }); 35 | 36 | clock.tick(123); 37 | }); 38 | }); 39 | -------------------------------------------------------------------------------- /test/workbox-core/sw/_private/test-waitUntil.mjs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import {waitUntil} from 'workbox-core/_private/waitUntil.mjs'; 10 | import {spyOnEvent} from '../../../../infra/testing/helpers/extendable-event-utils.mjs'; 11 | 12 | describe(`waitUntil()`, function () { 13 | const sandbox = sinon.createSandbox(); 14 | 15 | beforeEach(async function () { 16 | sandbox.restore(); 17 | }); 18 | 19 | after(async function () { 20 | sandbox.restore(); 21 | }); 22 | 23 | it(`adds an async function's returned promise to an event and returns it`, async function () { 24 | const event = new ExtendableEvent('install'); 25 | spyOnEvent(event); 26 | 27 | const promise = new Promise((resolve) => resolve('test')); 28 | const result = await waitUntil(event, () => promise); 29 | 30 | expect(result).to.equal('test'); 31 | expect(event.waitUntil.args[0][0]).to.equal(promise); 32 | }); 33 | }); 34 | -------------------------------------------------------------------------------- /test/workbox-core/sw/test-clientsClaim.mjs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import {clientsClaim} from 'workbox-core/clientsClaim.mjs'; 10 | 11 | describe(`clientsClaim`, function () { 12 | const sandbox = sinon.createSandbox(); 13 | 14 | afterEach(function () { 15 | sandbox.restore(); 16 | }); 17 | 18 | it(`should add an activate event listener that calls clientsClaim`, function () { 19 | const clientsClaimSpy = sandbox.stub(self.clients, 'claim'); 20 | 21 | sandbox.stub(self, 'addEventListener').callsFake((eventName, cb) => { 22 | expect(eventName).to.equal('activate'); 23 | cb(); 24 | expect(clientsClaimSpy.callCount).to.equal(1); 25 | }); 26 | 27 | clientsClaim(); 28 | }); 29 | }); 30 | -------------------------------------------------------------------------------- /test/workbox-core/sw/test-registerQuotaErrorCallback.mjs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import {registerQuotaErrorCallback} from 'workbox-core/registerQuotaErrorCallback.mjs'; 10 | 11 | describe(`registerQuotaErrorCallback()`, function () { 12 | it(`should throw when passed a non-function in dev mode`, async function () { 13 | if (process.env.NODE_ENV === 'production') this.skip(); 14 | 15 | await expectError(() => registerQuotaErrorCallback(null), 'incorrect-type'); 16 | }); 17 | }); 18 | -------------------------------------------------------------------------------- /test/workbox-expiration/static/expiration-plugin/example-1.txt: -------------------------------------------------------------------------------- 1 | example-1.txt 2 | -------------------------------------------------------------------------------- /test/workbox-expiration/static/expiration-plugin/example-2.txt: -------------------------------------------------------------------------------- 1 | example-2.txt 2 | -------------------------------------------------------------------------------- /test/workbox-expiration/static/expiration-plugin/sw-max-age-seconds.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | importScripts('/__WORKBOX/buildFile/workbox-core'); 10 | importScripts('/__WORKBOX/buildFile/workbox-expiration'); 11 | importScripts('/__WORKBOX/buildFile/workbox-routing'); 12 | importScripts('/__WORKBOX/buildFile/workbox-strategies'); 13 | importScripts('/infra/testing/comlink/sw-interface.js'); 14 | 15 | workbox.routing.registerRoute( 16 | /.*.txt/, 17 | new workbox.strategies.CacheFirst({ 18 | cacheName: 'expiration-plugin-max-age-seconds', 19 | plugins: [ 20 | new workbox.expiration.ExpirationPlugin({ 21 | maxAgeSeconds: 1, 22 | }), 23 | ], 24 | }), 25 | ); 26 | 27 | self.addEventListener('install', (event) => 28 | event.waitUntil(self.skipWaiting()), 29 | ); 30 | self.addEventListener('activate', (event) => 31 | event.waitUntil(self.clients.claim()), 32 | ); 33 | -------------------------------------------------------------------------------- /test/workbox-expiration/static/expiration-plugin/sw-max-entries.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | importScripts('/__WORKBOX/buildFile/workbox-core'); 10 | importScripts('/__WORKBOX/buildFile/workbox-expiration'); 11 | importScripts('/__WORKBOX/buildFile/workbox-routing'); 12 | importScripts('/__WORKBOX/buildFile/workbox-strategies'); 13 | importScripts('/infra/testing/comlink/sw-interface.js'); 14 | 15 | workbox.routing.registerRoute( 16 | /.*.txt/, 17 | new workbox.strategies.CacheFirst({ 18 | cacheName: 'expiration-plugin-max-entries', 19 | plugins: [ 20 | new workbox.expiration.ExpirationPlugin({ 21 | maxEntries: 1, 22 | }), 23 | ], 24 | }), 25 | ); 26 | 27 | self.addEventListener('install', (event) => 28 | event.waitUntil(self.skipWaiting()), 29 | ); 30 | self.addEventListener('activate', (event) => 31 | event.waitUntil(self.clients.claim()), 32 | ); 33 | -------------------------------------------------------------------------------- /test/workbox-navigation-preload/integration/test-sw.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | const {runUnitTests} = require('../../../infra/testing/webdriver/runUnitTests'); 10 | 11 | describe(`[workbox-navigation-preload]`, function () { 12 | it(`passes all SW unit tests`, async function () { 13 | await runUnitTests('/test/workbox-navigation-preload/sw/'); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /test/workbox-navigation-preload/static/sw-custom-header.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | importScripts('/__WORKBOX/buildFile/workbox-sw'); 10 | importScripts('/infra/testing/comlink/sw-interface.js'); 11 | 12 | workbox.setConfig({modulePathPrefix: '/__WORKBOX/buildFile/'}); 13 | 14 | // The header will be `Service-Worker-Navigation-Preload: custom-value`. 15 | workbox.navigationPreload.enable('custom-value'); 16 | 17 | // Once the service worker's taken control, it responds to navigations with 18 | // a synthetic response. 19 | // If Navigation Preload is enabled, that request bypasses the service worker. 20 | const navigationRoute = new workbox.routing.NavigationRoute( 21 | () => new Response('Generated by the service worker.'), 22 | ); 23 | workbox.routing.registerRoute(navigationRoute); 24 | 25 | self.addEventListener('install', () => self.skipWaiting()); 26 | self.addEventListener('activate', () => self.clients.claim()); 27 | -------------------------------------------------------------------------------- /test/workbox-navigation-preload/static/sw-default-header.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | importScripts('/__WORKBOX/buildFile/workbox-sw'); 10 | importScripts('/infra/testing/comlink/sw-interface.js'); 11 | 12 | workbox.setConfig({modulePathPrefix: '/__WORKBOX/buildFile/'}); 13 | 14 | // The header will be `Service-Worker-Navigation-Preload: true`. 15 | workbox.navigationPreload.enable(); 16 | 17 | // Once the service worker's taken control, it responds to navigations with 18 | // a synthetic response. 19 | // If Navigation Preload is enabled, that request bypasses the service worker. 20 | const navigationRoute = new workbox.routing.NavigationRoute( 21 | () => new Response('Generated by the service worker.'), 22 | ); 23 | workbox.routing.registerRoute(navigationRoute); 24 | 25 | self.addEventListener('install', () => self.skipWaiting()); 26 | self.addEventListener('activate', () => self.clients.claim()); 27 | -------------------------------------------------------------------------------- /test/workbox-navigation-preload/static/sw-disable.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | importScripts('/__WORKBOX/buildFile/workbox-sw'); 10 | importScripts('/infra/testing/comlink/sw-interface.js'); 11 | 12 | workbox.setConfig({modulePathPrefix: '/__WORKBOX/buildFile/'}); 13 | 14 | workbox.navigationPreload.disable(); 15 | 16 | // Once the service worker's taken control, it responds to navigations with 17 | // a synthetic response. 18 | // Since navigation preload is disabled, this response *should* be used. 19 | const navigationRoute = new workbox.routing.NavigationRoute( 20 | () => new Response('Generated by the service worker.'), 21 | ); 22 | workbox.routing.registerRoute(navigationRoute); 23 | 24 | self.addEventListener('install', () => self.skipWaiting()); 25 | self.addEventListener('activate', () => self.clients.claim()); 26 | -------------------------------------------------------------------------------- /test/workbox-navigation-preload/sw/test-isSupported.mjs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import {isSupported} from 'workbox-navigation-preload/isSupported.mjs'; 10 | 11 | describe(`isSupported`, function () { 12 | it(`should return true iff navigation preload is supported`, async function () { 13 | if (self.registration.navigationPreload) { 14 | expect(isSupported()).to.equal(true); 15 | } else { 16 | expect(isSupported()).to.equal(false); 17 | } 18 | }); 19 | }); 20 | -------------------------------------------------------------------------------- /test/workbox-precaching/integration/test-sw.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | const {runUnitTests} = require('../../../infra/testing/webdriver/runUnitTests'); 10 | 11 | describe(`[workbox-precaching]`, function () { 12 | it(`passes all SW unit tests`, async function () { 13 | await runUnitTests('/test/workbox-precaching/sw/'); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /test/workbox-precaching/static/addToCacheList.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |

precache.addToCacheList()

7 | 8 | 9 | 10 | 11 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /test/workbox-precaching/static/cleanup-outdated-caches/sw.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | importScripts('/__WORKBOX/buildFile/workbox-sw'); 10 | importScripts('/infra/testing/comlink/sw-interface.js'); 11 | 12 | workbox.setConfig({modulePathPrefix: '/__WORKBOX/buildFile/'}); 13 | 14 | workbox.precaching.precache([ 15 | { 16 | url: 'test.txt', 17 | revision: '1', 18 | }, 19 | ]); 20 | 21 | workbox.precaching.cleanupOutdatedCaches(); 22 | 23 | self.addEventListener('install', (event) => 24 | event.waitUntil(self.skipWaiting()), 25 | ); 26 | self.addEventListener('activate', (event) => 27 | event.waitUntil(self.clients.claim()), 28 | ); 29 | -------------------------------------------------------------------------------- /test/workbox-precaching/static/cleanup-outdated-caches/test.txt: -------------------------------------------------------------------------------- 1 | Testing. 2 | -------------------------------------------------------------------------------- /test/workbox-precaching/static/precache-and-update/hashed-file.abcd1234.txt: -------------------------------------------------------------------------------- 1 | This file will be requested by sw-2.js. 2 | -------------------------------------------------------------------------------- /test/workbox-precaching/static/precache-and-update/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | Test page for precache-and-update 4 | 9 | 10 | 11 | 12 |

Workbox Precaching - precache-and-update

13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /test/workbox-precaching/static/precache-and-update/styles/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: #2ecc71; 3 | } 4 | -------------------------------------------------------------------------------- /test/workbox-precaching/static/precache-and-update/sw-1.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | importScripts('/__WORKBOX/buildFile/workbox-sw'); 10 | importScripts('/infra/testing/comlink/sw-interface.js'); 11 | 12 | workbox.setConfig({modulePathPrefix: '/__WORKBOX/buildFile/'}); 13 | 14 | workbox.precaching.addPlugins([ 15 | new workbox.cacheableResponse.CacheableResponsePlugin({ 16 | statuses: [200], 17 | }), 18 | ]); 19 | 20 | workbox.precaching.precache([ 21 | { 22 | url: 'styles/index.css', 23 | revision: '1', 24 | }, 25 | { 26 | url: 'index.html', 27 | revision: '1', 28 | }, 29 | ]); 30 | 31 | workbox.precaching.addRoute(); 32 | 33 | self.addEventListener('install', (event) => 34 | event.waitUntil(self.skipWaiting()), 35 | ); 36 | self.addEventListener('activate', (event) => 37 | event.waitUntil(self.clients.claim()), 38 | ); 39 | -------------------------------------------------------------------------------- /test/workbox-precaching/static/precache-and-update/sw-2.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | importScripts('/__WORKBOX/buildFile/workbox-sw'); 10 | importScripts('/infra/testing/comlink/sw-interface.js'); 11 | 12 | workbox.setConfig({modulePathPrefix: '/__WORKBOX/buildFile/'}); 13 | 14 | workbox.precaching.precache([ 15 | { 16 | url: 'index.html', 17 | revision: '2', 18 | }, 19 | 'hashed-file.abcd1234.txt', 20 | ]); 21 | 22 | workbox.precaching.addRoute(); 23 | 24 | self.addEventListener('install', (event) => 25 | event.waitUntil(self.skipWaiting()), 26 | ); 27 | self.addEventListener('activate', (event) => 28 | event.waitUntil(self.clients.claim()), 29 | ); 30 | -------------------------------------------------------------------------------- /test/workbox-precaching/static/project/example-2.html: -------------------------------------------------------------------------------- 1 | Text from example-2.html 2 | -------------------------------------------------------------------------------- /test/workbox-precaching/static/project/example-a.html: -------------------------------------------------------------------------------- 1 | example-a.html 2 | -------------------------------------------------------------------------------- /test/workbox-precaching/static/project/example-b.html: -------------------------------------------------------------------------------- 1 | example-b.html 2 | -------------------------------------------------------------------------------- /test/workbox-precaching/static/project/example-timestamp.html: -------------------------------------------------------------------------------- 1 | Text from example-timestamp.html 2 | -------------------------------------------------------------------------------- /test/workbox-precaching/static/project/example.html: -------------------------------------------------------------------------------- 1 | Text from example.html 2 | -------------------------------------------------------------------------------- /test/workbox-precaching/static/project/index.html: -------------------------------------------------------------------------------- 1 | Text from index.html 2 | -------------------------------------------------------------------------------- /test/workbox-precaching/sw/resetDefaultPrecacheController.mjs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import {getOrCreatePrecacheController} from 'workbox-precaching/utils/getOrCreatePrecacheController.mjs'; 10 | 11 | export function resetDefaultPrecacheController() { 12 | const pc = getOrCreatePrecacheController(); 13 | 14 | pc._urlsToCacheKeys.clear(); 15 | pc._urlsToCacheModes.clear(); 16 | pc._cacheKeysToIntegrities.clear(); 17 | 18 | pc._installAndActiveListenersAdded = false; 19 | } 20 | -------------------------------------------------------------------------------- /test/workbox-precaching/sw/test-addPlugins.mjs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import {addPlugins} from 'workbox-precaching/addPlugins.mjs'; 10 | import {precache} from 'workbox-precaching/precache.mjs'; 11 | import {getOrCreatePrecacheController} from 'workbox-precaching/utils/getOrCreatePrecacheController.mjs'; 12 | 13 | describe(`addPlugins()`, function () { 14 | it(`should add plugins to the strategy`, async function () { 15 | const plugin1 = {}; 16 | const plugin2 = {}; 17 | 18 | precache([{url: '/', revision: null}]); 19 | addPlugins([plugin1]); 20 | 21 | const pc = getOrCreatePrecacheController(); 22 | expect(pc.strategy.plugins).to.include(plugin1); 23 | expect(pc.strategy.plugins).not.to.include(plugin2); 24 | 25 | addPlugins([plugin2]); 26 | 27 | expect(pc.strategy.plugins).to.include(plugin1); 28 | expect(pc.strategy.plugins).to.include(plugin2); 29 | }); 30 | }); 31 | -------------------------------------------------------------------------------- /test/workbox-precaching/sw/test-cleanupOutdatedCaches.mjs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import {cleanupOutdatedCaches} from 'workbox-precaching/cleanupOutdatedCaches.mjs'; 10 | import {resetDefaultPrecacheController} from './resetDefaultPrecacheController.mjs'; 11 | 12 | describe(`cleanupOutdatedCaches()`, function () { 13 | const sandbox = sinon.createSandbox(); 14 | 15 | beforeEach(async function () { 16 | sandbox.restore(); 17 | resetDefaultPrecacheController(); 18 | }); 19 | 20 | afterEach(function () { 21 | sandbox.restore(); 22 | }); 23 | 24 | it(`should add an activate listener`, async function () { 25 | const addEventListenerSpy = sandbox.spy(self, 'addEventListener'); 26 | cleanupOutdatedCaches(); 27 | 28 | expect(addEventListenerSpy.calledOnce).to.be.true; 29 | expect(addEventListenerSpy.firstCall.args[0]).to.eql('activate'); 30 | }); 31 | }); 32 | -------------------------------------------------------------------------------- /test/workbox-precaching/sw/utils/test-printInstallDetails.mjs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import {logger} from 'workbox-core/_private/logger.mjs'; 10 | import {printInstallDetails} from 'workbox-precaching/utils/printInstallDetails.mjs'; 11 | 12 | describe(`printInstallDetails()`, function () { 13 | const sandbox = sinon.createSandbox(); 14 | 15 | beforeEach(function () { 16 | if (logger) { 17 | sandbox.spy(logger, 'log'); 18 | } 19 | }); 20 | 21 | afterEach(function () { 22 | sandbox.restore(); 23 | }); 24 | 25 | it(`should print with single update`, function () { 26 | if (process.env.NODE_ENV === 'production') this.skip(); 27 | 28 | printInstallDetails([], ['/index.html']); 29 | 30 | expect(logger.log.callCount).to.equal(1); 31 | }); 32 | }); 33 | -------------------------------------------------------------------------------- /test/workbox-range-requests/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

You need to manually register sw.js

5 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /test/workbox-routing/integration/test-sw.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | const {runUnitTests} = require('../../../infra/testing/webdriver/runUnitTests'); 10 | 11 | describe(`[workbox-routing]`, function () { 12 | it(`passes all SW unit tests`, async function () { 13 | await runUnitTests('/test/workbox-routing/sw/'); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /test/workbox-routing/static/demo-img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GoogleChrome/workbox/e26d8d7507f9412ba029922f3d9920e68710f2cf/test/workbox-routing/static/demo-img.png -------------------------------------------------------------------------------- /test/workbox-routing/static/routing-basic/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

You need to manually register sw.js

5 | 6 | 7 | -------------------------------------------------------------------------------- /test/workbox-routing/static/routing-basic/sw.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | importScripts('/__WORKBOX/buildFile/workbox-core'); 10 | importScripts('/__WORKBOX/buildFile/workbox-routing'); 11 | 12 | // Use the same handler for each route, which will create a new response whose 13 | // body contains the original request URL. 14 | const handler = ({url}) => new Response(url); 15 | 16 | const routeObject = new workbox.routing.Route( 17 | ({url}) => url.pathname === '/routeObject', 18 | handler, 19 | ); 20 | workbox.routing.registerRoute(routeObject); 21 | 22 | workbox.routing.registerRoute('/sameOrigin', handler); 23 | 24 | workbox.routing.registerRoute('https://example.com/crossOrigin', handler); 25 | 26 | self.addEventListener('install', () => self.skipWaiting()); 27 | self.addEventListener('activate', () => self.clients.claim()); 28 | -------------------------------------------------------------------------------- /test/workbox-routing/static/routing-navigation/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

You need to manually register sw.js

5 | 6 | 7 | -------------------------------------------------------------------------------- /test/workbox-routing/static/routing-navigation/sw.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | importScripts('/__WORKBOX/buildFile/workbox-core'); 10 | importScripts('/__WORKBOX/buildFile/workbox-routing'); 11 | 12 | workbox.routing.registerRoute( 13 | new workbox.routing.NavigationRoute(({url}) => { 14 | return new Response(`NavigationRoute.${url.href}`); 15 | }), 16 | ); 17 | 18 | self.addEventListener('install', (event) => 19 | event.waitUntil(self.skipWaiting()), 20 | ); 21 | self.addEventListener('activate', (event) => 22 | event.waitUntil(self.clients.claim()), 23 | ); 24 | -------------------------------------------------------------------------------- /test/workbox-routing/static/routing-regex/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

Workbox Routing - routing-regex

5 |

You need to manually register sw.js

6 | 7 | 8 | -------------------------------------------------------------------------------- /test/workbox-routing/static/routing.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 9 | 10 | 11 |

Get Routing Replacing an Image.

12 | 13 | 14 | 15 | 16 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /test/workbox-routing/static/sw.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | importScripts( 10 | '../../../../packages/workbox-core/build/browser/workbox-core.dev.js', 11 | ); 12 | importScripts( 13 | '../../../../packages/workbox-routing/build/browser/workbox-routing.dev.js', 14 | ); 15 | 16 | const routing = self.workbox.routing; 17 | const Route = self.workbox.routing.Route; 18 | 19 | const specialImgURL = new URL( 20 | '/test/workbox-routing/static/demo-img.png', 21 | location, 22 | ).toString(); 23 | const specialImgRoute = new Route( 24 | ({event}) => { 25 | return event.request.url === specialImgURL; 26 | }, 27 | () => { 28 | return fetch( 29 | 'http://via.placeholder.com/300x300/ffffff/F57C00?text=Hello+from+Workbox', 30 | {mode: 'no-cors'}, 31 | ); 32 | }, 33 | ); 34 | routing.registerRoute(specialImgRoute); 35 | -------------------------------------------------------------------------------- /test/workbox-strategies/integration/test-sw.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | const {runUnitTests} = require('../../../infra/testing/webdriver/runUnitTests'); 10 | 11 | describe(`[workbox-strategies]`, function () { 12 | it(`passes all SW unit tests`, async function () { 13 | await runUnitTests('/test/workbox-strategies/sw/'); 14 | }); 15 | }); 16 | -------------------------------------------------------------------------------- /test/workbox-strategies/static/cache-first/example.txt: -------------------------------------------------------------------------------- 1 | hello 2 | -------------------------------------------------------------------------------- /test/workbox-strategies/static/cache-first/sw.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | importScripts('/__WORKBOX/buildFile/workbox-sw'); 10 | importScripts('/infra/testing/comlink/sw-interface.js'); 11 | 12 | workbox.setConfig({modulePathPrefix: '/__WORKBOX/buildFile/'}); 13 | 14 | workbox.routing.registerRoute( 15 | new RegExp('/test/workbox-strategies/static/cache-first/example.txt'), 16 | new workbox.strategies.CacheFirst(), 17 | ); 18 | 19 | self.addEventListener('install', (event) => 20 | event.waitUntil(self.skipWaiting()), 21 | ); 22 | self.addEventListener('activate', (event) => 23 | event.waitUntil(self.clients.claim()), 24 | ); 25 | -------------------------------------------------------------------------------- /test/workbox-strategies/static/cache-only/sw.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | importScripts('/__WORKBOX/buildFile/workbox-sw'); 10 | importScripts('/infra/testing/comlink/sw-interface.js'); 11 | 12 | workbox.setConfig({modulePathPrefix: '/__WORKBOX/buildFile/'}); 13 | 14 | workbox.routing.registerRoute( 15 | new RegExp('/CacheOnly/.*/'), 16 | new workbox.strategies.CacheOnly(), 17 | ); 18 | 19 | self.addEventListener('install', (event) => 20 | event.waitUntil( 21 | caches 22 | .open(workbox.core.cacheNames.runtime) 23 | .then((cache) => cache.put('/CacheOnly/InCache/', new Response('Cached'))) 24 | .then(() => self.skipWaiting()), 25 | ), 26 | ); 27 | self.addEventListener('activate', (event) => 28 | event.waitUntil(self.clients.claim()), 29 | ); 30 | -------------------------------------------------------------------------------- /test/workbox-strategies/static/network-first/sw.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | importScripts('/__WORKBOX/buildFile/workbox-sw'); 10 | importScripts('/infra/testing/comlink/sw-interface.js'); 11 | 12 | workbox.setConfig({modulePathPrefix: '/__WORKBOX/buildFile/'}); 13 | 14 | workbox.routing.registerRoute( 15 | new RegExp('/__WORKBOX/uniqueValue'), 16 | new workbox.strategies.NetworkFirst({ 17 | cacheName: 'network-first', 18 | }), 19 | ); 20 | 21 | self.addEventListener('install', (event) => { 22 | self.skipWaiting(); 23 | event.waitUntil( 24 | caches 25 | .open('network-first') 26 | .then((cache) => 27 | cache.put('/__WORKBOX/uniqueValue', new Response('Cached')), 28 | ), 29 | ); 30 | }); 31 | self.addEventListener('activate', (event) => 32 | event.waitUntil(self.clients.claim()), 33 | ); 34 | -------------------------------------------------------------------------------- /test/workbox-strategies/static/network-only/sw.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | importScripts('/__WORKBOX/buildFile/workbox-sw'); 10 | importScripts('/infra/testing/comlink/sw-interface.js'); 11 | 12 | workbox.setConfig({modulePathPrefix: '/__WORKBOX/buildFile/'}); 13 | 14 | workbox.routing.registerRoute( 15 | new RegExp('/__WORKBOX/uniqueValue'), 16 | new workbox.strategies.NetworkOnly({ 17 | cacheName: 'network-only', 18 | }), 19 | ); 20 | 21 | self.addEventListener('install', (event) => 22 | event.waitUntil( 23 | caches 24 | .open('network-only') 25 | .then((cache) => 26 | cache.put('/__WORKBOX/uniqueValue', new Response('Cached')), 27 | ) 28 | .then(() => self.skipWaiting()), 29 | ), 30 | ); 31 | self.addEventListener('activate', (event) => 32 | event.waitUntil(self.clients.claim()), 33 | ); 34 | -------------------------------------------------------------------------------- /test/workbox-strategies/static/stale-while-revalidate/sw.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | importScripts('/__WORKBOX/buildFile/workbox-sw'); 10 | importScripts('/infra/testing/comlink/sw-interface.js'); 11 | 12 | workbox.setConfig({modulePathPrefix: '/__WORKBOX/buildFile/'}); 13 | 14 | workbox.routing.registerRoute( 15 | new RegExp('/__WORKBOX/uniqueValue'), 16 | new workbox.strategies.StaleWhileRevalidate({ 17 | cacheName: 'stale-while-revalidate', 18 | }), 19 | ); 20 | 21 | self.addEventListener('install', (event) => 22 | event.waitUntil(self.skipWaiting()), 23 | ); 24 | self.addEventListener('activate', (event) => 25 | event.waitUntil(self.clients.claim()), 26 | ); 27 | -------------------------------------------------------------------------------- /test/workbox-streams/static/4.txt: -------------------------------------------------------------------------------- 1 | 4 2 | -------------------------------------------------------------------------------- /test/workbox-streams/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |

4 | You need to manually call 5 | navigator.serviceWorker.register('sw.js') 6 |

7 | 8 | 9 | -------------------------------------------------------------------------------- /test/workbox-streams/sw/test-isSupported.mjs: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import {isSupported} from 'workbox-streams/isSupported.mjs'; 10 | 11 | describe(`isSupported`, function () { 12 | it(`should return true when ReadableStream is available`, async function () { 13 | try { 14 | new ReadableStream({start() {}}); 15 | 16 | expect(isSupported()).to.be.true; 17 | } catch (error) { 18 | expect(isSupported()).to.be.false; 19 | } 20 | }); 21 | }); 22 | -------------------------------------------------------------------------------- /test/workbox-sw/static/example.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: 'green'; 3 | } 4 | -------------------------------------------------------------------------------- /test/workbox-sw/static/example.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | window.example = 1 + 1; 10 | -------------------------------------------------------------------------------- /test/workbox-sw/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 |

Testing Loading of Workbox via CDN

18 |

This page will register a service worker that uses the Workbox CDN.

19 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /test/workbox-sw/static/integration/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 |

You need to manually register sw.js

5 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /test/workbox-sw/static/integration/invalid-sw.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | importScripts('/__WORKBOX/buildFile/workbox-sw'); 10 | importScripts('/infra/testing/comlink/sw-interface.js'); 11 | 12 | workbox.setConfig({modulePathPrefix: '/__WORKBOX/buildFile/'}); 13 | 14 | // This is expected to lead to an error. 15 | const namespace = 'doesnotexist'; 16 | const module = self.workbox[namespace]; 17 | if (!module) { 18 | throw new Error(`self.workbox.${namespace} did not load anything.`); 19 | } 20 | -------------------------------------------------------------------------------- /test/workbox-sw/static/integration/valid-sw.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | importScripts('/__WORKBOX/buildFile/workbox-sw'); 10 | importScripts('/infra/testing/comlink/sw-interface.js'); 11 | 12 | workbox.setConfig({modulePathPrefix: '/__WORKBOX/buildFile/'}); 13 | 14 | // TODO: Find some way to autogenerate this list. 15 | const namespaces = [ 16 | 'backgroundSync', 17 | 'broadcastUpdate', 18 | 'cacheableResponse', 19 | 'core', 20 | 'expiration', 21 | 'googleAnalytics', 22 | 'precaching', 23 | 'rangeRequests', 24 | 'routing', 25 | 'strategies', 26 | ]; 27 | 28 | for (const namespace of namespaces) { 29 | const module = self.workbox[namespace]; 30 | if (!module) { 31 | throw new Error( 32 | `$self.workbox.{namespace} did not load the expected interface.`, 33 | ); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /test/workbox-sw/static/sw.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | importScripts('../../../packages/workbox-sw/build/browser/workbox-sw.js'); 10 | 11 | const wb = new self.WorkboxSW({ 12 | modulePathCb: (moduleName, debug) => { 13 | const build = debug ? 'dev' : 'prod'; 14 | return `../../../packages/${moduleName}/build/browser/${moduleName}.${build}.js`; 15 | }, 16 | }); 17 | 18 | wb.skipWaiting(); 19 | wb.clientsClaim(); 20 | 21 | wb.core.setLogLevel(self.workbox.core.LOG_LEVELS.debug); 22 | 23 | wb.precaching.precache(['example.css', 'example.js']); 24 | -------------------------------------------------------------------------------- /test/workbox-webpack-plugin/node/v4/lib/create-webpack-asset-plugin.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | // A small helper class to generate a "fake" webpack asset for testing purposes. 10 | // Roughly equivalent to https://www.npmjs.com/package/generate-asset-webpack-plugin, 11 | // but this uses the webpack v4 syntax. 12 | 13 | class CreateWebpackAssetPlugin { 14 | constructor(name) { 15 | if (typeof name !== 'string') { 16 | throw new Error('Please pass in a string.'); 17 | } 18 | this.name = name; 19 | } 20 | 21 | apply(compiler) { 22 | compiler.hooks.emit.tap( 23 | this.constructor.name, 24 | (compilation) => 25 | (compilation.assets[this.name] = { 26 | source: () => this.name, 27 | size: () => this.name.length, 28 | }), 29 | ); 30 | } 31 | } 32 | 33 | module.exports = CreateWebpackAssetPlugin; 34 | -------------------------------------------------------------------------------- /test/workbox-webpack-plugin/node/v5/lib/create-webpack-asset-plugin.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | const {sources} = require('webpack'); 10 | 11 | class CreateWebpackAssetPlugin { 12 | constructor(name) { 13 | if (typeof name !== 'string') { 14 | throw new Error('Please pass in a string.'); 15 | } 16 | this.name = name; 17 | } 18 | 19 | apply(compiler) { 20 | compiler.hooks.thisCompilation.tap(this.constructor.name, (compilation) => 21 | compilation.emitAsset(this.name, new sources.RawSource(this.name)), 22 | ); 23 | } 24 | } 25 | 26 | module.exports = CreateWebpackAssetPlugin; 27 | -------------------------------------------------------------------------------- /test/workbox-webpack-plugin/node/v5/static/expected-service-worker.js.map: -------------------------------------------------------------------------------- 1 | {"version":3,"sources":["webpack://workbox/./test/workbox-webpack-plugin/static/sw-src.js"],"names":["workbox","precaching","precacheAndRoute","self","__WB_MANIFEST"],"mappings":"AAQA,QAAQ,WAAW,iBAAiB,4DAAK,cAAe","file":"service-worker.js","sourceRoot":"","sourcesContent":["/*\n Copyright 2018 Google LLC\n\n Use of this source code is governed by an MIT-style\n license that can be found in the LICENSE file or at\n https://opensource.org/licenses/MIT.\n*/\n\nworkbox.precaching.precacheAndRoute(self.__WB_MANIFEST, {});\n"]} 2 | -------------------------------------------------------------------------------- /test/workbox-webpack-plugin/static/bad-multiple-injection.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | // Multiple entries. 10 | workbox.precaching.precacheAndRoute(self.__WB_MANIFEST); 11 | workbox.precaching.precacheAndRoute(self.__WB_MANIFEST); 12 | -------------------------------------------------------------------------------- /test/workbox-webpack-plugin/static/example-project-1/images/example-jpeg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GoogleChrome/workbox/e26d8d7507f9412ba029922f3d9920e68710f2cf/test/workbox-webpack-plugin/static/example-project-1/images/example-jpeg.jpg -------------------------------------------------------------------------------- /test/workbox-webpack-plugin/static/example-project-1/images/web-fundamentals-icon192x192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/GoogleChrome/workbox/e26d8d7507f9412ba029922f3d9920e68710f2cf/test/workbox-webpack-plugin/static/example-project-1/images/web-fundamentals-icon192x192.png -------------------------------------------------------------------------------- /test/workbox-webpack-plugin/static/example-project-1/page-1.html: -------------------------------------------------------------------------------- 1 |

Page 1

2 | -------------------------------------------------------------------------------- /test/workbox-webpack-plugin/static/example-project-1/page-2.html: -------------------------------------------------------------------------------- 1 |

Page 2

2 | -------------------------------------------------------------------------------- /test/workbox-webpack-plugin/static/example-project-1/splitChunksEntry.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import expect from 'chai'; 10 | 11 | console.log({expect}); 12 | -------------------------------------------------------------------------------- /test/workbox-webpack-plugin/static/example-project-1/styles/stylesheet-1.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: red; 3 | } 4 | -------------------------------------------------------------------------------- /test/workbox-webpack-plugin/static/example-project-1/styles/stylesheet-2.css: -------------------------------------------------------------------------------- 1 | body { 2 | background-color: blue; 3 | } 4 | -------------------------------------------------------------------------------- /test/workbox-webpack-plugin/static/example-project-1/webpackEntry.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | console.log('I am an entry.'); 10 | -------------------------------------------------------------------------------- /test/workbox-webpack-plugin/static/injected-manifest.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Google LLC 3 | Use of this source code is governed by an MIT-style 4 | license that can be found in the LICENSE file or at 5 | https://opensource.org/licenses/MIT. 6 | */ 7 | 8 | module.exports = self.__WB_MANIFEST; 9 | -------------------------------------------------------------------------------- /test/workbox-webpack-plugin/static/injected-manifest.json: -------------------------------------------------------------------------------- 1 | self.__WB_MANIFEST 2 | -------------------------------------------------------------------------------- /test/workbox-webpack-plugin/static/module-import-sw.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import {precacheAndRoute} from '../../../packages/workbox-precaching'; 10 | 11 | precacheAndRoute(self.__WB_MANIFEST); 12 | -------------------------------------------------------------------------------- /test/workbox-webpack-plugin/static/sw-src-define-plugin.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2020 Google LLC 3 | Use of this source code is governed by an MIT-style 4 | license that can be found in the LICENSE file or at 5 | https://opensource.org/licenses/MIT. 6 | */ 7 | 8 | // This is used to validate the DefinePlugin's replacement. 9 | const prefix = __PREFIX__; 10 | workbox.core.setCacheNameDetails({prefix}); 11 | 12 | workbox.precaching.precacheAndRoute(self.__WB_MANIFEST, {}); 13 | -------------------------------------------------------------------------------- /test/workbox-webpack-plugin/static/sw-src-missing-sourcemap.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | /* eslint-disable */ 10 | workbox.precaching.precacheAndRoute(self.__WB_MANIFEST, {}); 11 | //# sourceMappingURL=does-not-exist.js.map 12 | -------------------------------------------------------------------------------- /test/workbox-webpack-plugin/static/sw-src.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | workbox.precaching.precacheAndRoute(self.__WB_MANIFEST, {}); 10 | -------------------------------------------------------------------------------- /test/workbox-webpack-plugin/static/sw.ts: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | // At the moment, this is just used to test the extension renaming. 10 | workbox.precaching.precacheAndRoute(self.__WB_MANIFEST, {}); 11 | -------------------------------------------------------------------------------- /test/workbox-webpack-plugin/static/wasm-project/add.wasm: -------------------------------------------------------------------------------- 1 | asm`add 2 |  j -------------------------------------------------------------------------------- /test/workbox-webpack-plugin/static/wasm-project/index.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | new Worker('./worker.js', {type: 'module'}); 10 | -------------------------------------------------------------------------------- /test/workbox-webpack-plugin/static/wasm-project/worker.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2018 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | import('./add.wasm').then(({add}) => { 10 | console.log(add(10, 20)); 11 | }); 12 | -------------------------------------------------------------------------------- /test/workbox-window/window/sw-error.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | thisShouldThrow(); // eslint-disable-line 10 | -------------------------------------------------------------------------------- /test/workbox-window/window/sw-message-reply.js: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright 2019 Google LLC 3 | 4 | Use of this source code is governed by an MIT-style 5 | license that can be found in the LICENSE file or at 6 | https://opensource.org/licenses/MIT. 7 | */ 8 | 9 | addEventListener('install', () => skipWaiting()); 10 | 11 | addEventListener('message', async (event) => { 12 | if (event.data.type === 'RESPOND_TO_MESSAGE') { 13 | event.ports[0].postMessage('Reply from SW!'); 14 | } else if (event.data.type === 'POST_MESSAGE_BACK') { 15 | const windows = await clients.matchAll({ 16 | type: 'window', 17 | includeUncontrolled: true, 18 | }); 19 | for (const win of windows) { 20 | const channel = new MessageChannel(); 21 | win.postMessage('postMessage from SW!', [channel.port1]); 22 | } 23 | } else if (event.data.type === 'BROADCAST_BACK') { 24 | const bc = new BroadcastChannel('workbox'); 25 | bc.postMessage('BroadcastChannel from SW!'); 26 | } 27 | }); 28 | --------------------------------------------------------------------------------