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.

Service workers fail to load

See original GitHub issue
  • I have read the contribution documentation for this project.
  • I agree to follow the code of conduct that this project follows, as appropriate.
  • I have searched the issue tracker for an issue that matches the one I want to file, without success.

Please describe your issue:

I’m trying to introduce service workers to a project that uses electron-forge, however I ran into an issue where the service worker script fails to load with the following error (in the browser window console):

error when registering service worker TypeError: Failed to register a ServiceWorker: A bad HTTP response code (-1) was received when fetching the script.

Screenshot: screen shot 2017-04-26 at 10 31 55 pm

The same code successfully loads the service worker script and registers it when run with electron .

I tried manually installing electron-prebuilt-compile and using that binary to load my code, and it fails. However, using the electron-prebuilt binary works. I did try using the .compilerc at https://github.com/electron/electron-compile#how-can-i-compile-only-some-file-types-but-not-others to stop compiling JS (since I thought it may be an issue caused by transpilation), but still got the same error.

Console output when you run electron-forge with the environment variable DEBUG=electron-forge:*. (Instructions on how to do so here). Please include the stack trace if one exists.

Arics-MacBook-Pro:esw aric$ DEBUG=electron-forge:* electron-forge start
WARNING: DEBUG environment variable detected.  Progress indicators will be sent over electron-forge:lifecycle
  electron-forge:lifecycle Process Started: Checking your system +0ms
  electron-forge:lifecycle Process Succeeded: Checking your system +17ms
  electron-forge:runtime-config setting key: verbose to value: false +13ms
WARNING: DEBUG environment variable detected.  Progress indicators will be sent over electron-forge:lifecycle
  electron-forge:lifecycle Process Started: Locating Application +0ms
  electron-forge:project-resolver searching for project in: /Users/aric/src/esw +2ms
  electron-forge:project-resolver electron-forge compatible package.json found in /Users/aric/src/esw/package.json +6ms
  electron-forge:lifecycle Process Succeeded: Locating Application +1ms
  electron-forge:lifecycle Process Started: Preparing native dependencies +1ms
  electron-forge:lifecycle Process Succeeded: Preparing native dependencies +176ms
  electron-forge:hook could not find hook: generateAssets +14ms
  electron-forge:lifecycle Process Started: Launching Application +2ms
  electron-forge:lifecycle Process Succeeded: Launching Application +7ms
2017-04-26 22:21:57.543 Electron Helper[17241:636606] Couldn't set selectedTextBackgroundColor from default ()

What command line arguments are you passing?

none

What does your config.forge data in package.json look like?

"config": {
    "forge": {
      "make_targets": {
        "win32": [
          "squirrel"
        ],
        "darwin": [
          "zip"
        ],
        "linux": [
          "deb",
          "rpm"
        ]
      },
      "electronPackagerConfig": {},
      "electronWinstallerConfig": {
        "name": "esw"
      },
      "electronInstallerDebian": {},
      "electronInstallerRedhat": {},
      "github_repository": {
        "owner": "",
        "name": ""
      },
      "windowsStoreConfig": {
        "packageName": "",
        "name": "esw"
      }
    }
  }

Please provide either a failing minimal testcase (with a link to the code) or detailed steps to reproduce your problem. Using electron-forge init is a good starting point, if that is not the source of your problem.

I have a repo that demonstrates this issue at https://github.com/concreted/esw, to be run with electron-forge start. When I run with electron . it successfully registers the service worker, but with electron-forge start it fails.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
MarshallOfSoundcommented, Apr 27, 2017

Never actually tried to use service workers with electron-compile, probably need a similar setup to our webview logic.

https://github.com/electron-userland/electron-forge/wiki/Using-‘preload’-scripts

Will look into it when I get a change, unless @paulcbetts has any ideas for this 👍

0reactions
concretedcommented, May 2, 2017

@MarshallOfSound yup after some digging it looks related to the interceptBufferProtocol call. @deepak1556 says he sees the issue in electron and will fix there.

Going to close this, thanks for your help @MarshallOfSound and @paulcbetts ❤️

Read more comments on GitHub >

github_iconTop Results From Across the Web

Service worker Failed to load resource: net - Stack Overflow
just to know that my service-worker.js is in the root of the website, works fine on home page no errors on chrome console,...
Read more >
Failed to load service-worker.js #97 - vuejs-templates/pwa
I have an error after a fresh install. Here is the steps: init a PWA project; host it on a https server; reach...
Read more >
Safari WebExtension does not load - Apple Developer
When I build WebExtension in Xcode and load it within Safari, I get non-specific error that service_worker could not be loaded due to...
Read more >
Service worker in production - Angular
Without a service worker, there is no guarantee that lazily loaded code is from the same version as the application's initial code. The...
Read more >
service worker controlled pages sometimes fail to load and ...
Another theory: The ssl cert associated with the site is expiring between when its cached by the service worker and returned in the...
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