Comments (16)
Ahhh thank you so much, reading the example I discovered this was related to the Karma.conf.js
not my main.ts
I had one other unrelated problem and I have my unit tests successfully running know
from karma-electron.
Started digging into this again, wanted to find out exactly what part of contextIsolation
was breaking (e.g. we're not really sending any traffic between the main electron
process and our renderer)
After some digging, saw some postMessage
events which weren't receiving origin
(which is good for security checks)
It turns out this is part of contextIsolation
but apparently there's another flag we can set:
{
webPreferences: {
nativeWindowOpen: true
}
}
which also seems to resolve the issues for a require
-free Electron:
electron/electron#9340 (comment)
https://www.electronjs.org/docs/api/window-open#using-chromes-windowopen-implementation
Going to more robustly test that setting (maybe even rollback the contextIsolation
wording) and update the documentation (if it all seems accurate)
from karma-electron.
It definitely should be supported. Unsure what's causing that error. Will triage by the end of the weekend
from karma-electron.
Thanks, I'd really appreciate it!
from karma-electron.
Looking into this now
from karma-electron.
I've reproduced electron@12
failing, though the error message I'm seeing from npm test
isn't quite what you've got
26 03 2021 19:57:58.898:INFO [launcher]: Launching browser ElectronWithNodeIntegration with unlimited concurrency
26 03 2021 19:57:58.902:INFO [launcher]: Starting browser Electron
26 03 2021 19:57:59.300:INFO [Electron 12.0.2 (Node 14.16.0)]: Connected on socket FInyO26cds6C8OkIAAAA with id 69134456
26 03 2021 19:58:01.302:WARN [Electron 12.0.2 (Node 14.16.0)]: Disconnected (1 times), because no message in 2000 ms.
Electron 12.0.2 (Node 14.16.0) ERROR
Disconnected, because no message in 2000 ms.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
from karma-electron.
When I run in continuous mode (npm run test-karma-continuous
), it does show the same error -- though oddly only in the browser console
from karma-electron.
Adding contextIsolation: false
to my webPreferences
fixes it. Now I need to read up more on that and:
- Figure out if that's the right fix
- Figure out if it's something to tell people to use, build into the repo, or both
https://stackoverflow.com/a/55908510/1960509
from karma-electron.
It looks like contextIsolation
started defaulting to true
in Electron@12 so it's most likely the correct switch:
https://www.electronjs.org/docs/tutorial/context-isolation
It does seem related to nodeIntegration
which we've documented in our README as an explicit opt-in
https://github.com/twolfson/karma-electron/tree/6.3.3#forcing-nodeintegration-support
That was regarding a workaround for preload
though and preload
was introduced in Electron@5 back 2 years ago:
https://www.electronjs.org/blog/electron-5-0
Digging into my own README now...
from karma-electron.
Since we don't set loadScriptsViaRequire
to true
by default, it seems like people aren't meant to have a guarantee for window.require
, so it does sound like this is another option to document in the examples
But still pushing people towards using preload
instead of these overrides
Going to still keep on reading a bit more (maybe play with preload
in tests) but prob settling on that
from karma-electron.
Yea, I think the thought process is:
- People will want to stay 1:1 with their existing Electron setup, so if they're using their
webPreferences
withnodeIntegration
andcontextIsolation
already set, then they'll keep using it - Otherwise, they'll figure out their own solution
- But since we're a test runner, we're not prescriptive
Going ahead with documentation only
from karma-electron.
This has been documented in 6.3.4
. Thanks for raising the issue =)
from karma-electron.
Hmm, I might have spoken too soon -- test-karma-no-node-integration
is failing in CI
from karma-electron.
Hmm, yea -- I think missing contextIsolation
is also affecting the karma-electron
bridge to the terminal somehow (which is why my console.log
never were showing up
I'm out of time to dig into this tonight but we do have a workaround for now as documented:
// Inside custom launcher
browserWindowOptions: {
webPreferences: {
contextIsolation: false
}
}
from karma-electron.
Glad to hear that got it working =D Going to leave this issue open as we've still got broken CI to look into
from karma-electron.
Alright, settled on nativeWindowOpen: true
as default always (released in 7.0.0
, just in case it's a breaking change)
and updated documentation to better explain 2 getting started mechanisms (non-extended config, Node.js + custom config)
from karma-electron.
Related Issues (20)
- How to use with karma-babel? HOT 27
- `electron` did show not nothing happen then HOT 1
- Can't import nodejs modules in an angular-cli project (Typescript) HOT 1
- Errors without stack traces coming from karma-electron? HOT 5
- running with ndb for debugging? HOT 2
- Unable to open Electron window using --show HOT 3
- Electron 5 nodeIntegration HOT 12
- Custom launcher `require` mechanism doesn't work HOT 4
- Module paths are messed up HOT 5
- Error: Karma plugin is meant to be used from within Angular CLI and will not work correctly outside of it HOT 1
- How to configure NODE_PATH for the Electron instance? HOT 24
- [feature] option like 'require', but for renderer processes. HOT 1
- Karma times out when using Electron 9 and client.useIframe = false HOT 20
- Non-context aware native modules in renderer will cause specs to error HOT 3
- electron V12.0.4---------require is not defined HOT 3
- ES Modules HOT 2
- "require is not defined" after update to karma-electron 7 / electron 12 HOT 12
- Regardless of the `browserWindowOptions.show` value, a window always opens. HOT 12
- sqlite3 stalls with nodeIntegration true contextIsolation false HOT 12
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from karma-electron.