Skip to content

backgroundThrottling: false not obeyed in Electron 4+ #20974

Closed

Description

@mbman

Preflight Checklist

  • I have read the Contributing Guidelines for this project.
  • I agree to follow the Code of Conduct that this project adheres to.
  • I have searched the issue tracker for an issue that matches the one I want to file, without success.

Issue Details

  • Electron Version:
    All versions starting from 4
  • Operating System:
    Tested on Win 10, don't know if other platforms are affected.
  • Last Known Working Electron version:
    3.1.13

Expected Behavior

When an electron window is opened with backgroundThrottling: false set in webPreferences it shouldn't throttle setTimeout while window is minimized, but it does throttle it.

Actual Behavior

Minimized window's setTimeout is throttled, despite disabling it.

To Reproduce

Please load the Electron Fiddle: https://gist.github.com/987afc63925e8ab2ad9c1e02dd7c3309 and follow instructions in the opened window.

Screenshots

Additional Information

Possible similar issue: #17402

Activity

  1. codebytere commented on Nov 6, 2019

    @codebytere
    Member

    @mbman i believe this was fixed in #20239, but was not backported. I'll see if I can get some backports up to address this in versions 7 and 6.

  2. mbman commented on Nov 7, 2019

    @mbman
    Author

    @codebytere thanks for the info - does that PR also fixes window.setBackgroundThrottling() not working?

  3. codebytere commented on Nov 7, 2019

    @codebytere
    Member

    That'll be fixed by the PR i put up a little while ago: #21037

  4. Nantris commented on Jan 8, 2020

    @Nantris
    Contributor

    #21037 says it's backported to 6.1.x, but I'm getting document.visibilityState === 'hidden' when my window is minimized or hidden on 6.1.7 - any thoughts?

    Much more strangely, static content in my BrowserWindows disappears when I focus a separate window in my project and many other oddities, 3 shown below

    image

    Even more strangely, this worked properly for me exactly once when I tested it andd ensured I was getting the expected visibilityState, then I packaged the app to give it a shot, didn't work, plus the weird behaviors.

    Came back to development, didn't work there either, but no weird behaviors. No changes to any files, dependencies or otherwise.


    Edit: I've only seen these issues very sporadically now, but no amount of restarting fixed it the day I made this comment. Very strange. Will update if I encounter it again or discover more details.

  5. Nantris commented on Jan 10, 2020

    @Nantris
    Contributor

    Unfortunately I continue seeing this issue and the visibilityState continues to return unexpected results. You can see here the effects. The cursor updates in response to the underlying content, but that content is not visible (default, pointer, text). Note that when the cursor is missing in this video, it is a text selection cursor but the screen recorder doesn't capture that cursor.

    The failure to render contents can occur at any time in any application window or multiple application windows. Any ideas about this? Is this not actually fixed in Electron 6.1.x?

    The issue occurs with and without GPU rasterization available ('enabled' & unavailable_off), which surprises me. Sending a signal to update the contents of a window via ipc will briefly restore for a split second, and then they're empty windows again. The more windows backgroundThrottling is disabled for, seemingly the worse the issue gets. This possibly only affects windows with a preload script, though I don't have enough data to do anything but make a slightly educated guess there. I managed to run into this in development for the first time today.

    Edit: Persists in Electron 7. The weird content disappearing bug seems to only occur in the following circumstances over 99% of the time:

    1. At least 3 BrowserWindow
    2. Developer tools is open for at least 1 BrowserWindow
  6. Nantris commented on Jul 7, 2020

    @Nantris
    Contributor

    @sofianguy @codebytere this persists in Electron 8.2.5 or the docs are wrong.

    document.visibilityState === "hidden" when the docs say this should not occur.


    From the docs:

    If backgroundThrottling is disabled, the visibility state will remain visible even if the window is minimized, occluded, or hidden.


    image

    This happens when I minimize or hide a window. I've tried the following, and the issue persists:

    • Creating the window with webPreferences.backgroundThrottling: false
    • win.setBackgroundThrottling(false)
    • win.webContents.setBackgroundThrottling(false)

    Unfortunately there's no win.getBackgroundThrottling() for me to see what the renderer thinks its own state is supposed to be.

    This is creating big issues for us with lag when users show the window for our app, because operations that are intended to happen when the window is hidden don't occur reliably, and instead they need to be done when the user shows the window.


    Tested on Windows 7 with Electron 8.2.5.

  7. crypto-dump commented on Jan 31, 2023

    @crypto-dump

    @slapbox is this issue resolved? I also have same problem

  8. Nantris commented on Jan 31, 2023

    @Nantris
    Contributor

    It was still an issue the last time I tested in 18.3.x

    @deepak1556 @codebytere I don't think this should be closed because #21037 doesn't seem to resolve the issue - unless the documentation I'm relying on was incorrect.

  9. hlevring commented on Feb 21, 2024

    @hlevring

    I think this might have finally gotten resolved in V 28.0.0

    https://www.electronjs.org/blog/electron-28-0#behavior-changed-webcontentsbackgroundthrottling-set-to-false-affects-all-webcontents-in-the-host-browserwindow

    I just had a 10 sec look and could really find the related PR, but it's definitely described as something that should fix this issue I think

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions