You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
"backgroundThrottling: false" no longer affects requestAnimationFrame() in background applications #9567
Operating system: Mac OS Sierra 10.12.4, El Capitan 10.11.6, 11.2.3 Mac OS Big Sur
Expected behavior
Disabling background throttling should prevent the slowdowns/pausing of both animation frames and intervals/timeouts when the window is in the background.
... should allow RAF to run without getting stopped or otherwise throttled when the window is in the background (minimized or completely obscured by other windows). Behavior specific to RAF on this issue was added in 0.37.6 (#4925)
Actual behavior
Behavior that depends on RAF calls will slow to a crawl when the window becomes obscured by other windows or is otherwise made a "background" window, behaving no differently whether backgroundThrottling is set to true or false. It reverts to normal behavior as soon as it becomes a foreground window again.
@Stickywes do you mean to say that behavior depending on RAF will slow to a crawl even when the application is running in the foreground? Or is this issue only experienced when in the background? Thanks.
Things are great if it's in the foreground! This issue only arises when the application window becomes obscured or minimized. RAF calls resume their normal rate as soon as the application is visible again.
changed the title [-]"backgroundThrottling: false" no longer affects requestAnimationFrame()[/-][+]"backgroundThrottling: false" no longer affects requestAnimationFrame() in background applications[/+]on May 24, 2017
I have tried the webPreferences option 'backgroundThrottling: false', app.commandLine.appendSwitch('disable-renderer-backgrounding'),
and win.setMinimizable(true) —in all cases requestAnimationFrame stops getting called when the window is inactive.
electron version: 1.6.11
OS: macOS El Capitan 10.11.6
Edit: setInterval() does work in the background with backgroundThrottling: false —so that may be a workaround for some.
In commit 497f5a1 (a part of Electron v1.5.0), osr_render_widget_host_view_mac.mm was changed to reflect Chromium API changes. This could be what introduced the bug. But I might be wrong here because I don't know low level Electron well enough. 😄
This is the associated Chromium change. Search for browser_compositor_view_mac.mm.
Additionally, the member variable disable_hidden_ set in atom_api_web_contents.cc is not found in the corresponding Chromium class or any class it inherits from, which is a little mind boggling. Where does Chromium use the disable_hidden_ property?
If anyone can drop some knowledge on this, that'd be awesome.
Updating the description to call out known workarounds, since that was kind of buried in my original description. Also adding westoncb's setInterval() comment.
Any news of this issue? I currently still using electron 1.4.x but my user encounter some cpu/ram problem with webGL, wich are better managed in the 1.7/8.
However my app has to still working during a workspace change or when it is minimized, i can't sacrifice this feature for mac users.
It's still not fixed! Using latest electron. This issue is so annoying. Aslo the lack of ownership of all the issues electron has. Literally every second feature has issues...
One step toward a solution would be to provide an example that demonstrates the issue, and provide details like the Operating System and OS version you're using.
Also need this. I have an older app thats on Electron 9.0.3 and disabling background throttling just fine. Now I've started a new app and version 14.X doesn't work.
We do robotics and our application streams positional data to our controller. When the app goes into the background this means our robotic kinematics stops even though in previous electron versions it would continue running. We cannot have our motion paths stop just because the window becomes hidden. Sticking to electron 9.X until this is resolved.
I always used the app.commandLine.appendSwitch('disable-renderer-backgrounding') but the backgroundThrottling flag also does not work for me. Can this issue get reopened as its not fixed?
@jrj2211 might be worth opening a new issue, this one is 4.5 years old now, but you might be well equipped to provide a proper test case that could prove out that it's broken (or at least find out what is needed to make the test case work properly in modern)
@ericblade I'm working on creating test apps and I'll start a new issue if I get a better idea of whats going on. I am perplexed though because I can't get consistent results. I created a fresh electron project with just this:
I started with Electron V14 and it was getting throttled. I've stepped back through each version of electron down to V7 at which point it stopped throttling. I changed back to V12 and V14, and its no longer throttling there either. No code changes, just did "npm install [email protected]" to change versions. I'm printing out the electron version on start to ensure its actually switching electron versions. Now I can't get it to throttle in my test example... I do not have electron installed globally so not sure whats going on there. I did also see a few times where the loop was just reduced speed (once per second) and sometimes it wouldn't start the loop until the window was visible but then was fine to minimize.
I did find that the only thing that had an effect for RAF was backgroundThrottling. The commandline arguments did nothing for RAF as far as I could tell, but did work for fixing throttling on setInterval/setTimeout.
I'm also trying this with a fresh electron-forge app and the same settings/code as above. Turns out I can't get it to stop throttling with any version of electron. I believe this might be an issue with electron forge and not electron though as I can get it to work with just a simple electron app (despite being inconsistent). My actual app is using electron-forge so I'm most interested in figuring out if these are separate issues.
There's definitely more testing to be done here, but I just wanted to log my current finding as I need to move onto other stuff. Using a normal setInterval loop will work for me for the time being.
a normal setInterval loop will work for me for the time being.
Aren't Interval timers also throttled by Chrome? or is that something that I remember from one of the many customized versions i've worked on in the past...
finally some happenings here. Looking forward the solution. It's been years and it's still not working properly. For me it's on windows 10, i have an invisible window that is getting throttled as soon as the gaming application is in focus.
I am not sure if this will resolve the issues with requestAnimationFrame, but for setInterval the below worked.
A bunch of code omitted, but this worked for our project. I explicitly set throttling to false on Main and all Render processes.
Built as Windows 10 executable
function createWorkerWindows(title: string): BrowserWindow {
const workerWindow = new BrowserWindow({
webPreferences: {
backgroundThrottling: false,
},
});
createProtocol("app");
workerWindow.hide();
workerWindow.minimize();
workerWindow.setMovable(false);
workerWindow.setFocusable(false);
workerWindow.setEnabled(false);
//the above seem to set throttling to true so call this last to set back to false
workerWindow.webContents.setBackgroundThrottling(false);
return workerWindow;
}
If you're facing requestAnimationFrame() isn't working in background, you may try to comment that line before compile electron.
Just trial and error way, so I can't promise it works :')
Well, I am not familiar electron and chromium codebase, but It works for my use case currently(at least).
I'd like to develop html canvas game. Multiplayer one at it too. Turn based.
While opponents will wait for each others move, they will surely like to do a quick peek, into someone else's websites.
This breaks animation.
Breaks my game too!
And this bug is closed!? Oh no, it is alive, well, kicking and breaking peoples dreams!
Edit: Its not just OS, Firefox has it too
Reacted by Jerry Green, Alexyoe, Tom Leamon and Arsenic Bismuth
Is there any known solution to this problem? I am in the same boat as @GrzesiekKozdroj - I am developing a game using electron, and having RAF stop when the game is not in focus is more or less a show stopper for me.
EDIT: Setting backgroundThrottling: false actually just works for me, so this seems to be fixed, at least for me (win 10, standard Electron installation)
I'm doing game as well. It does not work for me. When my canvas is in the current screen which is the main application, everything runs smoothly. If I switch to another application which put the screen in the background, the animation gets noticeably choppier. But when I click back into my app, it fixes itself. I am testing this on two separate monitors. I'm developing for Windows. This bug is not fixed.
I've also done the following "hacks", which do not work:
Silent audio track that is loop
Have a setInterval function
Have the animation being processed in worker threads
Background throttling is false in the switches and setting it in the BrowserWindow
I'm doing game as well. It does not work for me. When my canvas is in the current screen which is the main application, everything runs smoothly. If I switch to another application which put the screen in the background, the animation gets noticeably choppier. But when I click back into my app, it fixes itself. I am testing this on two separate monitors. I'm developing for Windows. This bug is not fixed.
I've also done the following "hacks", which do not work:
Silent audio track that is loop
Have a setInterval function
Have the animation being processed in worker threads
Background throttling is false in the switches and setting it in the BrowserWindow
Sacrificed a Zebra to the Chromium gods
nada works.
good luck brother.
This ticket is 7 years old. I suggest you creating a new ticket. Noone will check old tockets from the team.
Give yourself a better chance with a new ticket.
Activity
LukePulverenti commentedon May 24, 2017
@Stickywes do you mean to say that behavior depending on RAF will slow to a crawl even when the application is running in the foreground? Or is this issue only experienced when in the background? Thanks.
WesWedding commentedon May 24, 2017
Things are great if it's in the foreground! This issue only arises when the application window becomes obscured or minimized. RAF calls resume their normal rate as soon as the application is visible again.
I've updated the issue description for clarity.
[-]"backgroundThrottling: false" no longer affects requestAnimationFrame()[/-][+]"backgroundThrottling: false" no longer affects requestAnimationFrame() in background applications[/+]georgewoo-nsuslab commentedon Jul 4, 2017
Are there any progress in this issue? I'm facing exactly the same problem in
electron version: 1.6.10
OS: macOS Sierra 10.12.5
Even if the backgroundThrottling option of BrowserWindow was set to false, animation stops when the application window runs in the background.
westoncb commentedon Jul 4, 2017
Same problem here:
I have tried the webPreferences option 'backgroundThrottling: false', app.commandLine.appendSwitch('disable-renderer-backgrounding'),
and win.setMinimizable(true) —in all cases requestAnimationFrame stops getting called when the window is inactive.
electron version: 1.6.11
OS: macOS El Capitan 10.11.6
Edit: setInterval() does work in the background with backgroundThrottling: false —so that may be a workaround for some.
neurosnap commentedon Jul 25, 2017
Any updates on this issue?
StevenEBarbaro commentedon Jul 26, 2017
Don't know if this will help, but I tried the repro on two environments:
Can't reproduce on Windows 8
Can reproduce on El Capitan 10.11.6
stephenou commentedon Aug 15, 2017
After doing some research:
In commit 497f5a1 (a part of Electron v1.5.0), osr_render_widget_host_view_mac.mm was changed to reflect Chromium API changes. This could be what introduced the bug. But I might be wrong here because I don't know low level Electron well enough. 😄
This is the associated Chromium change. Search for
browser_compositor_view_mac.mm.Additionally, the member variable
disable_hidden_set in atom_api_web_contents.cc is not found in the corresponding Chromium class or any class it inherits from, which is a little mind boggling. Where does Chromium use thedisable_hidden_property?If anyone can drop some knowledge on this, that'd be awesome.
WesWedding commentedon Aug 16, 2017
Updating the description to call out known workarounds, since that was kind of buried in my original description. Also adding westoncb's setInterval() comment.
prixe commentedon Jan 30, 2018
Any news of this issue? I currently still using electron 1.4.x but my user encounter some cpu/ram problem with webGL, wich are better managed in the 1.7/8.
However my app has to still working during a workspace change or when it is minimized, i can't sacrifice this feature for mac users.
I have tried :
without success.
It's really annoying and this regression was introduced a long time ago. So if you can fix it ❤️
29 remaining items
iamisti commentedon Aug 16, 2021
It's still not fixed! Using latest electron. This issue is so annoying. Aslo the lack of ownership of all the issues electron has. Literally every second feature has issues...
WesWedding commentedon Aug 17, 2021
One step toward a solution would be to provide an example that demonstrates the issue, and provide details like the Operating System and OS version you're using.
joezappie commentedon Aug 31, 2021
Also need this. I have an older app thats on Electron 9.0.3 and disabling background throttling just fine. Now I've started a new app and version 14.X doesn't work.
We do robotics and our application streams positional data to our controller. When the app goes into the background this means our robotic kinematics stops even though in previous electron versions it would continue running. We cannot have our motion paths stop just because the window becomes hidden. Sticking to electron 9.X until this is resolved.
I always used the app.commandLine.appendSwitch('disable-renderer-backgrounding') but the backgroundThrottling flag also does not work for me. Can this issue get reopened as its not fixed?
OS: Windows 10 (19043)
ericblade commentedon Aug 31, 2021
@jrj2211 might be worth opening a new issue, this one is 4.5 years old now, but you might be well equipped to provide a proper test case that could prove out that it's broken (or at least find out what is needed to make the test case work properly in modern)
if you do, make sure you tag back here :)
joezappie commentedon Aug 31, 2021
@ericblade I'm working on creating test apps and I'll start a new issue if I get a better idea of whats going on. I am perplexed though because I can't get consistent results. I created a fresh electron project with just this:
renderer.js
main.js
I started with Electron V14 and it was getting throttled. I've stepped back through each version of electron down to V7 at which point it stopped throttling. I changed back to V12 and V14, and its no longer throttling there either. No code changes, just did "npm install [email protected]" to change versions. I'm printing out the electron version on start to ensure its actually switching electron versions. Now I can't get it to throttle in my test example... I do not have electron installed globally so not sure whats going on there. I did also see a few times where the loop was just reduced speed (once per second) and sometimes it wouldn't start the loop until the window was visible but then was fine to minimize.
I did find that the only thing that had an effect for RAF was backgroundThrottling. The commandline arguments did nothing for RAF as far as I could tell, but did work for fixing throttling on setInterval/setTimeout.
I'm also trying this with a fresh electron-forge app and the same settings/code as above. Turns out I can't get it to stop throttling with any version of electron. I believe this might be an issue with electron forge and not electron though as I can get it to work with just a simple electron app (despite being inconsistent). My actual app is using electron-forge so I'm most interested in figuring out if these are separate issues.
There's definitely more testing to be done here, but I just wanted to log my current finding as I need to move onto other stuff. Using a normal setInterval loop will work for me for the time being.
ericblade commentedon Sep 1, 2021
Aren't Interval timers also throttled by Chrome? or is that something that I remember from one of the many customized versions i've worked on in the past...
iamisti commentedon Sep 1, 2021
finally some happenings here. Looking forward the solution. It's been years and it's still not working properly. For me it's on windows 10, i have an invisible window that is getting throttled as soon as the gaming application is in focus.
James-AltaML commentedon Nov 30, 2021
https://developer.chrome.com/blog/timer-throttling-in-chrome-88/#javascript-timers
I am not sure if this will resolve the issues with requestAnimationFrame, but for setInterval the below worked.
A bunch of code omitted, but this worked for our project. I explicitly set throttling to false on Main and all Render processes.
Built as Windows 10 executable
package.json
background.ts
https://www.electronjs.org/docs/latest/api/browser-window#page-visibility
It seems that any property/function that affects visibility will enable background throttling.
At the time of posting this, I haven't had time to fully test whether all the functions called / properties set affect throttling, so I may have went overboard.
Aaqu commentedon Jan 20, 2022
I have similar problem, steps:
Platform:
Electron 16.0.7
MacOs Monterey
I write simple fiddle
https://gist.github.com/f813a71d185cf5b0f16baf4155c9f74d
App works when I add to BrowserWindow
alwaysOnTop: true, it is not a good solutionmain.js
index.html
c0re100 commentedon May 7, 2022
If you're facing
requestAnimationFrame()isn't working in background, you may try to comment that line before compile electron.Just trial and error way, so I can't promise it works :')
Well, I am not familiar electron and chromium codebase, but It works for my use case currently(at least).
GrzesiekKozdroj commentedon Jul 6, 2022
I'd like to develop html canvas game. Multiplayer one at it too. Turn based.
While opponents will wait for each others move, they will surely like to do a quick peek, into someone else's websites.
This breaks animation.
Breaks my game too!
And this bug is closed!? Oh no, it is alive, well, kicking and breaking peoples dreams!
Edit: Its not just OS, Firefox has it too
GGAlanSmithee commentedon Jun 8, 2024
Is there any known solution to this problem? I am in the same boat as @GrzesiekKozdroj - I am developing a game using electron, and having RAF stop when the game is not in focus is more or less a show stopper for me.
EDIT: Setting
backgroundThrottling: falseactually just works for me, so this seems to be fixed, at least for me (win 10, standard Electron installation)ProdigyView commentedon Dec 21, 2024
I'm doing game as well. It does not work for me. When my canvas is in the current screen which is the main application, everything runs smoothly. If I switch to another application which put the screen in the background, the animation gets noticeably choppier. But when I click back into my app, it fixes itself. I am testing this on two separate monitors. I'm developing for Windows. This bug is not fixed.
I've also done the following "hacks", which do not work:
nada works.
iamisti commentedon Dec 22, 2024
good luck brother.
This ticket is 7 years old. I suggest you creating a new ticket. Noone will check old tockets from the team.
Give yourself a better chance with a new ticket.
fix: replace requestAnimationFrame with setInterval to fix macOS desk…