Can't install the service worker in Electron renderers with `nodeIntegration` enabled
See original GitHub issueDescribe the bug
Invoking worker.start()
in an Electron renderer fails if nodeIntegration
is enabled. This happens because process
is defined, which causes isNodeProcess
to return true. As a result, it’s not possible to use msw
in these windows. (msw
’s node server doesn’t work in that environment either, since fetch
calls use the Chromium network stack, not Node’s.)
Electron provides process.type
with value "renderer"
in these situations. Would it be satisfactory for isNodeProcess
to return false in that case? If so, I’m happy to put up a PR!
Environment
msw: 0.27.1
nodejs: 12.18.3
npm: 7.6.3
Please also provide your browser version.
Electron 11.3.0 / Chromium 87
To Reproduce
Steps to reproduce the behavior:
- Create Electron
BrowserWindow
withnodeIntegration: true
- Create an
msw
service worker and invokeworker.start()
- Open DevTools, view Console
- See error:
[MSW] Failed to execute `setupWorker` in a non-browser environment. Consider using `setupServer` for Node.js environment instead.
Expected behavior
Service worker is installed
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
How can I register a Service Worker in Electron when node ...
I have finally figured out how to use a service worker if node integration is enabled for both the renderer thread as well...
Read more >最新趨勢觀測站- electron service worker的推薦與評價
electron service worker 在Can't install the service worker in Electron renderers . ... in an Electron renderer fails if nodeIntegration is enabled.
Read more >Electron release notes
Added support for Webauthn discoverable keys (aka resident keys), allowing users to authenticate without first having to select or type a username.
Read more >Quick Start with Electron using React — Realm
This page contains information to get Realm integrated into your Electron application quickly by developing an application using Create React App.
Read more >Electron Node Integration - Quasar v1
js resources from within the “renderer” thread (the UI). It is enabled by default in Quasar CLI, although Electron is encouraging developers to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@kettanaito it looks like the new lib is-node-process, which msw relies upon, doesn’t have this change
If I understood correctly, this was the accepted fix?
I think there has been a regression. I’m not able to run msw in Electron anymore.