Headless Electron


#1

We wrote an Electron app that works flawlessly on both mac and windows. Everyone is super happy (the mac was a bonus, windows was the real target).

Then the client brings up a requirement that entails running the app in “headless mode”. Basically a single function of the app should run periodically in the background regardless of whether the app is open or not.

Shouldn’t be too hard we think, just use process.argv to figure out which mode the app should run in and setup a cronjob on the mac and a scheduled task on windows.

And that’s where things start falling over. It works flawlessly on the mac, the browser window is not invoked, the background function is called ( entails a series of network calls and some business logic ) and ends up calling app.quit().

On windows however the background function is only able to make a single network call, the callback then just hangs on the following network call. The only way to get it to run to completion is to invoke a browser window which is obviously not an option for a background service. I assume that the event loop on windows is dependent on the browser window or something?

So it looks like we will have to resort to .NET. Horrible times, Electron was so much fun!

Since Electron was not created with this in mind I can’t really complain or file a bug or anything. But I thought it might be beneficial to have this written up somewhere - maybe there’s a workaround we’re not seeing - maybe this saves some other poor fool from following in our footsteps.

All the best and here’s hoping we get to play with Electron again soon.


Run electron apps on Linux VPS
#2

Ehm, what about simply using node without the whole electron framework? If it isn’t going to be visible (headless), you might just aswell write your “headless” application as a regular commandline script in javascript/node.


#3

Well we will always need both. So basically we would install both Electron and Node in the same distributable. I’ll give it a shot, thanks.


#4

Yea you could have a main executable that checks your run mode and executes either the Electron GUI or the node script. Shouldn’t have much of a drawback really, if the functionality is easily transferred.


#5

Thanks, any recommendations for the node distributable to include? I need to make a single download - the target machines are pretty much vanilla windows. I’ve seen this https://jaredallard.me/nexe/ but I’d rather have the code shared between electron and node. I think nexe bundles it separately?


#6

+1 for headless!

As far I understood there is the same run-time used for booth: node-js and client to share the context. What would it take to just forward code to the traditional v8 as in Node.js? a headless version isn’t just great for testing but also for packaging (enclose & nexec won’t do it in ages!).

please! any pointers are welcome!


#7

I’d really like to see a headless option. Sort of like phantom JS. I’d like to be able to run test inside of chromium but without any window actually rendering to the screen.


#8

Yup, I’ll put in a +1 for headless as well, as it’s functionality that I know I will want in the near future. Sounds like we’re already good to go on OS X, but Windows is a bit sketchier?


#9

Any update on this? Could really use a headless option for electron as well. Nodejs scriot is not quite the same as it either needs node to be installed on the host machine or needs to use something like nexe. Both not quite ideal.


#10

+1 for headless as well. This is the primary use case for an app I’m building, and it really needs to run as a service on hundreds of systems, in a cross-platform environment. Currently we’re just using node scripts, but it would be great to have the option of a UI, and nice asar packaging.