#54311: fix: stop a hidden page rendering after setBackgroundThrottling is re-enabled
Description of Change
Before: calling webContents.setBackgroundThrottling(false) and then setBackgroundThrottling(true) on a page nobody can see (window hidden, minimized or occluded) left the page producing frames at full rate, reporting document.visibilityState === 'visible' and running unthrottled timers until the window's visibility next changed. The same happened if throttling was disabled first and the window hidden afterwards.
After: re-enabling throttling puts the page straight back into its real visibility state, so it stops rendering and throttles like any other hidden page.
How:
WebContents::SetBackgroundThrottling(true)now re-hides theRenderWidgetHosts (via the view, mirroringWebContentsImpl::SetPrimaryMainFrameViewVisibility, including cross-process iframe widgets) when the page's computed visibility is hidden. Previously only thefalsedirection touched the widget, and content only re-hides on a visibility transition, which never comes for an already-hidden page. Captured / picture-in-picture pages are left painting. The setting is applied to every frame's widget and RenderView, asHandleNewRenderFramealready does, and thefalsedirection shows the child-frame widgets too.allow_disabling_blink_scheduler_throttling_per_renderview.patch:WebViewImplremembers the visibility the browser last asked for and re-applies it whenSetSchedulerThrottlingflips, instead of waiting for the next lifecycle update; the forced-visible state is also reported toWebViewObservers so media is not left background-paused.- Specs: hide then toggle off/on; toggle off, hide, toggle on, show; a cross-site iframe; and a muted looping video, asserting frames stop/resume and
document.visibilityStatefollows.
Follow-up to #52844, which fixed the false direction.
Checklist
- I have built and tested this change
- I have filled out the PR description
- I have reviewed and verified the changes
- tests are changed or added
- PR release notes describe the change in a way relevant to app developers, and are capitalized, punctuated, past tense, and no longer than 80 characters.
Release Notes
Notes: Fixed hidden windows continuing to render at full frame rate after setBackgroundThrottling(false) followed by setBackgroundThrottling(true).
Backports
Semver Impact
Semantic Versioning helps users understand the impact of updates:
- Major (X.y.z): Breaking changes that may require code modifications
- Minor (x.Y.z): New features that maintain backward compatibility
- Patch (x.y.Z): Bug fixes that don't change the API
- None: Changes that don't affect using facing parts of Electron