Avoid app throttling when Electron is in background


#1

Consider the following example:

setInterval(function()
{
   console.log(new Date());
});

If I run it with electron example.js under OS X, it opens up an icon in my dockbar and starts printing out the time on the console. If the app is not focused, however, after a while it starts throttling.

I looked around and found that this is due to OS X power saving strategy. Now, what if I needed it to keep working in background? My app will be a daemon doing a little bit of something every now and then, and I can’t have my users blankly staring at my app for ages.

I found out here that I can do

electron.powerSaveBlocker.start('prevent-app-suspension');

Which actually fixes my problem. This however, is quite invasive, since as far as my understanding goes it prevents the system from sleeping at all! I don’t need this much, I would just need my app to do something when the computer is active and online without forcing it to stay awake forever.

Isn’t there anything in the middle, between having my users keeping the app continuously in the foreground, and making their computer sleepless forever?


Keep the browser window running while not-active
#2

There is app.commandLine.appendSwitch('disable-renderer-backgrounding') but you need to call it before app.on('ready'...) inside the main process.


#3

Oh wow, great! I found this moments ago though: https://github.com/atom/electron/issues/4925

Looks like it’s on the roadmap :slight_smile: I came here from my topic so looking forward to seeing if this baby get’s added.

Edit: Added a request here in Chromium’s Bit Bucket: https://bitbucket.org/chromiumembedded/cef/issues/1864/adding-requestanimationframe-to-disable