Let Chromium manage document.visibilityState
and document.hidden
Chromium already includes the necessary plumbing to manage the visibility properties and `visibilitychange` event so this gets rid of most of our custom logic for `BrowserWindow` and `BrowserView`. Note that `webview` remains unchanged and is still affected by the issues listed below. User facing changes: - The `document` visibility properties and `visibilitychange` event are now also updated/fired in response to occlusion changes on macOS. In other words, `document.visibilityState` will now be `hidden` on macOS if the window is occluded by another window. - Previously, `visibilitychange` was also fired by *both* Electron and Chromium in some cases (e.g. when hiding the window). Now it is only fired by Chromium so you no longer get duplicate events. - The visiblity state of `BrowserWindow`s created with `{ show: false }` is now initially `visible` until the window is shown and hidden. - The visibility state of `BrowserWindow`s with `backgroundThrottling` disabled is now permanently `visible`. This should also fix #6860 (but not for `webview`).
This commit is contained in:
parent
d40a7569cc
commit
7d2226e05e
11 changed files with 175 additions and 90 deletions
|
@ -97,6 +97,25 @@ child.once('ready-to-show', () => {
|
|||
})
|
||||
```
|
||||
|
||||
### Page visibility
|
||||
|
||||
The [Page Visibility API][page-visibility-api] works as follows:
|
||||
|
||||
* On all platforms, the visibility state tracks whether the window is
|
||||
hidden/minimized or not.
|
||||
* Additionally, on macOS, the visibility state also tracks the window
|
||||
occlusion state. If the window is occluded (i.e. fully covered) by another
|
||||
window, the visibility state will be `hidden`. On other platforms, the
|
||||
visibility state will be `hidden` only when the window is minimized or
|
||||
explicitly hidden with `win.hide()`.
|
||||
* If a `BrowserWindow` is created with `show: false`, the initial visibility
|
||||
state will be `visible` despite the window actually being hidden.
|
||||
* If `backgroundThrottling` is disabled, the visibility state will remain
|
||||
`visible` even if the window is minimized, occluded, or hidden.
|
||||
|
||||
It is recommended that you pause expensive operations when the visibility
|
||||
state is `hidden` in order to minimize power consumption.
|
||||
|
||||
### Platform notices
|
||||
|
||||
* On macOS modal windows will be displayed as sheets attached to the parent window.
|
||||
|
@ -294,7 +313,8 @@ It creates a new `BrowserWindow` with native properties as set by the `options`.
|
|||
* `minimumFontSize` Integer (optional) - Defaults to `0`.
|
||||
* `defaultEncoding` String (optional) - Defaults to `ISO-8859-1`.
|
||||
* `backgroundThrottling` Boolean (optional) - Whether to throttle animations and timers
|
||||
when the page becomes background. Defaults to `true`.
|
||||
when the page becomes background. This also affects the
|
||||
[Page Visibility API][#page-visibility]. Defaults to `true`.
|
||||
* `offscreen` Boolean (optional) - Whether to enable offscreen rendering for the browser
|
||||
window. Defaults to `false`. See the
|
||||
[offscreen rendering tutorial](../tutorial/offscreen-rendering.md) for
|
||||
|
@ -1326,6 +1346,7 @@ removed in future Electron releases.
|
|||
removed in future Electron releases.
|
||||
|
||||
[blink-feature-string]: https://cs.chromium.org/chromium/src/third_party/WebKit/Source/platform/RuntimeEnabledFeatures.json5?l=62
|
||||
[page-visibility-api]: https://developer.mozilla.org/en-US/docs/Web/API/Page_Visibility_API
|
||||
[quick-look]: https://en.wikipedia.org/wiki/Quick_Look
|
||||
[vibrancy-docs]: https://developer.apple.com/reference/appkit/nsvisualeffectview?language=objc
|
||||
[window-levels]: https://developer.apple.com/reference/appkit/nswindow/1664726-window_levels
|
||||
|
|
|
@ -60,12 +60,11 @@ container when used with traditional and flexbox layouts (since v0.36.11). Pleas
|
|||
do not overwrite the default `display:flex;` CSS property, unless specifying
|
||||
`display:inline-flex;` for inline layout.
|
||||
|
||||
`webview` has issues being hidden using the `hidden` attribute or using `display: none;`.
|
||||
It can cause unusual rendering behaviour within its child `browserplugin` object
|
||||
and the web page is reloaded, when the `webview` is un-hidden, as opposed to just
|
||||
becoming visible again. The recommended approach is to hide the `webview` using
|
||||
CSS by zeroing the `width` & `height` and allowing the element to shrink to the 0px
|
||||
dimensions via `flex`.
|
||||
`webview` has issues being hidden using the `hidden` attribute or using
|
||||
`display: none;`. It can cause unusual rendering behaviour within its child
|
||||
`browserplugin` object and the web page is reloaded when the `webview` is
|
||||
un-hidden. The recommended approach is to hide the `webview` using
|
||||
`visibility: hidden`.
|
||||
|
||||
```html
|
||||
<style>
|
||||
|
@ -75,9 +74,7 @@ dimensions via `flex`.
|
|||
height:480px;
|
||||
}
|
||||
webview.hide {
|
||||
flex: 0 1;
|
||||
width: 0px;
|
||||
height: 0px;
|
||||
visibility: hidden;
|
||||
}
|
||||
</style>
|
||||
```
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue