segment-boneyard / nightmare

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

Possible to run nightmare.js in an electron application? #915

Closed josephrocca closed 7 years ago

josephrocca commented 8 years ago

To put it briefly, I've got an electron project and I'd like to use nightmare instances within this project. Is this possible? Currently I'm using a <webview> tag and ipc to do all my automation but it's a bit of a mess and nightmare is just so sleek in comparison so I'm hoping this is possible.

For context, the reason I'm using electron is because it's really easy to display the results of test and scrapes live and I can use libraries like chart.js rather than just console.loging messages.

So far as I understand, nightmare just uses an electron BrowserWindow under the hood, so this should be quite easy? But I guess nightmare tries to create a whole new electron instance rather than just a BrowserWindow and the main electron instance doesn't like that? If that's the case, is there a way to tell a new nightmarejs instance that there's already an electron instance running, and to pass it a reference so it doesn't try create a new one?

My most minimal test was just:

console.log("starting")
let Nightmare = require('nightmare');
let nightmare = new Nightmare({ openDevTools: { mode: 'detach' }, show: true });
nightmare.goto('http://github.com').then(() => { console.log("done") })

That works fine with node ., but running it with electron . doesn't work - it just outputs 'starting' to the console.

Thanks!

Siilwyn commented 8 years ago

Please search for existing issues before creating a new one, see: https://github.com/segmentio/nightmare/issues/856

josephrocca commented 8 years ago

Ah, thanks. Sorry about that

josephrocca commented 7 years ago

For the benefit of those who arrive here via search, there's another thread here with potential workarounds until this is solved: https://github.com/segmentio/nightmare/issues/1018

casesandberg commented 7 years ago

Closing this as a dupe of #856