segment-boneyard / nightmare

A high-level browser automation library.
https://open.segment.com
19.55k stars 1.08k forks source link

Controlling an existing Electron app with Nightmare #574

Closed jviotti closed 7 years ago

jviotti commented 8 years ago

Hi, we're trying to do something crazy here at https://github.com/resin-io/etcher. We're trying to automate the process of taking screenshots to our application (for the website, etc) by controlling the real Electron app with Nightmare.

The plan is to run the Etcher app with Nightmare utilities to drive the application into certain states, and take screenshots of it.

So far I tried the following:

jviotti commented 8 years ago

Actually, not even process is defined. Looks like the app is running in a more restricted environment, and not in a normal Electron environment?

jviotti commented 8 years ago
screenshot 2016-04-15 11 16 57
jviotti commented 8 years ago

In this comment, the user seems to be running scripts using require() with NightmareJS. I'll try various NightmareJS versions to see if it makes any difference.

jviotti commented 8 years ago

Okay, I found the reason. nodeIntegration is set to false on runner.js: https://github.com/segmentio/nightmare/blob/master/lib/runner.js#L71. Setting it to true works like a charm. Any reason why this is disables? I'm happy to provide a PR to implement an option to control this value.

Mr0grog commented 8 years ago

Any reason why this is disables?

Well, Nightmare is primarily meant to be a scripted web browser, and loading any content from the web into an environment where nodeIntegration = true makes your whole machine extremely vulnerable to all manner of crazy attacks.

I’m not a committer or anything here, so I can’t say anything about whether other people might be interested in making this happen. Personally, though, I’m sure making that property changeable is really the best way to go about this. Using Nightmare (or something like it or its API) to control an Electron app is a really cool idea, but I think doing it right would require a much more thoughtful approach. Maybe better to fork it, make all the adjustments you wind up needing to make it work well for you, and come back with ideas about what actually worked out well (or not) in practice?

rosshinkley commented 7 years ago

Closing as this as like @Mr0grog said, that isn't really what Nightmare is intended for. There may be a future where this is doable, but not for now.

Mr0grog commented 7 years ago

Github also released Spectron sometime after this issue was originally posted. It’s probably a much better way to accomplish this stuff.