question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Better documentation for mode as a replacement for setConfig()

See original GitHub issue

Library Affected: workbox-cli 5.0.0 - generateSW command

Browser & Platform: all browsers

Issue or Feature Request Description: I am migrating from 4.3.1 to 5.0.0 and tried the inlineWorkboxRuntime option. However I am getting Uncaught (in promise) ReferenceError: workbox is not defined. for v5 cli. Facing this error inside the file mentioned under importScripts option.

Workbox 4.3.1 importWorkboxFrom: "local", importScripts: ["sw-custom.js"]

Workbox 5.0.0 inlineWorkboxRuntime: true, importScripts: ["sw-custom.js"]

Content of sw-custom.js workbox.setConfig({ debug: true });

This is because workbox is being minified and workbox as a variable is not available. I can see some minified variables like G,g,B,T etc in the debugger for the ServiceWorkerGlobalScope.

Possible Fix I think the inlineWorkboxRuntime option also needs to minify contents of importScripts option.

Please let me know if you need any further inputs from my end.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:4
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
jeffposnickcommented, Feb 27, 2020

You can set mode: 'development' or mode: 'production' in the v5 generateSW configuration to toggle between the Workbox runtime that has extra logging enabled and disabled.

Sorry about that not being clear; we should add something to https://developers.google.com/web/tools/workbox/guides/migrations/migrate-from-v4 to call this change out explicitly.

0reactions
jeffposnickcommented, Mar 11, 2020
  1. I’m not sure that that’s a reasonable assumption. If you want to use Workbox in that fashion, I’d recommend switching to the injectManifest mode. In that mode, you have full control over the contents of your service worker file (including inlining whatever code you want), and Workbox just handles replacing the self.__WB_MANIFEST variable with the actual precache manifest based on your build config.

  2. Folks have historically used importScripts for pulling in non-Workbox code, like code for push notifications. They can continue doing that in v5 with inlineWorkboxRuntime: true if they want. Disallowing that entirely would be too strict.

For your particular use case, I think you’re going to have a better time switching to injectManifest and following the info at https://developers.google.com/web/tools/workbox/guides/using-bundlers to create a bundle of your service worker file using ES imports.

Read more comments on GitHub >

github_iconTop Results From Across the Web

pbjs.setConfig(options) for Header Bidding
Turn on send all bids mode; Configure send bids control; Bid cache; Set the order in which bidders are called; Set the page...
Read more >
Set Config - Zebra Technologies TechDocs
SET_CONFIG. Used to create, update or replace a DataWedge Profile and its settings, and can configure multiple options with a single intent action....
Read more >
Mode
Mode. Providing the mode configuration option tells webpack to use its built-in optimizations accordingly. string = 'production': 'none' | 'development' ...
Read more >
Setting Configuration - CKEditor 4 Documentation
Learn how to install, integrate and configure CKEditor 4. More complex aspects, like creating plugins, widgets and skins are explained here, too.
Read more >
Create a configuration page - Teams
setConfig() are set, as defined by the Config interface. ... let urlParams = new URLSearchParams(document.location.search.substring(1)); let ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found