Code Monkey home page Code Monkey logo

Comments (16)

prince-chrismc avatar prince-chrismc commented on July 2, 2024 1

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

🤗 Thank you for the help!

from karma-electron.

twolfson avatar twolfson commented on July 2, 2024 1

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.

twolfson avatar twolfson commented on July 2, 2024

It definitely should be supported. Unsure what's causing that error. Will triage by the end of the weekend

from karma-electron.

prince-chrismc avatar prince-chrismc commented on July 2, 2024

Thanks, I'd really appreciate it!

from karma-electron.

twolfson avatar twolfson commented on July 2, 2024

Looking into this now

from karma-electron.

twolfson avatar twolfson commented on July 2, 2024

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.

twolfson avatar twolfson commented on July 2, 2024

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.

twolfson avatar twolfson commented on July 2, 2024

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.

twolfson avatar twolfson commented on July 2, 2024

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.

twolfson avatar twolfson commented on July 2, 2024

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.

twolfson avatar twolfson commented on July 2, 2024

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 with nodeIntegration and contextIsolation 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.

twolfson avatar twolfson commented on July 2, 2024

This has been documented in 6.3.4. Thanks for raising the issue =)

https://github.com/twolfson/karma-electron/tree/6.3.4#forcing-nodeintegration-and-contextisolation-support

from karma-electron.

twolfson avatar twolfson commented on July 2, 2024

Hmm, I might have spoken too soon -- test-karma-no-node-integration is failing in CI

from karma-electron.

twolfson avatar twolfson commented on July 2, 2024

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.

twolfson avatar twolfson commented on July 2, 2024

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.

twolfson avatar twolfson commented on July 2, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.