[10] [DFN[[[Page Visibility]]]] は、[[Webページ]]が表示されているかどうかに関する機能です。

;; [20] 略称「[DFN[[[pagevis]]]]」で呼ばれることがあります。

* 仕様書

[REFS[
- [31] [CITE@en[Page Visibility (Second Edition)]] ([TIME[2015-11-13 18:23:52 +09:00]] 版) <https://w3c.github.io/page-visibility/>
]REFS]

* API

[11] [[Page Visibility]] では次の [[API]] が定義されています。
[FIG(middle list)[
- [CODE(JS)@en[[[document.hidden]]]]
- [CODE(JS)@en[[[document.visibilityState]]]]
- [CODE(DOMe)@en[[[visibilitychange]]]]
]FIG]

* 歴史

[REFS[
- [12] [CITE['''['''whatwg''']''' Proposal for a tab visibility API]] ([TIME[2011-01-01 07:21:50 +09:00]] 版) <http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2010-December/029382.html>
- [13] [CITE['''['''whatwg''']''' Proposal for a tab visibility API]] ([TIME[2011-04-30 19:13:31 +09:00]] 版) <http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2011-April/031353.html>
- [14] [CITE@en-US[Web Performance Working Group]] ([TIME[2012-08-08 13:31:20 +09:00]] 版) <http://www.w3.org/2011/04/webperf.html>
]REFS]

[15] 最初この仕様は [[Chrome]] 開発チームから [[WHATWG]] に提案されました (>>12) が、
[[Ian Hickson]] は時期尚早であり、また [[HTML]] より [[CSSOM]] に属するべきであるとしました (>>13)。
この間に新たに設立された [[W3C]] の [[Web Performance Working Group]] に持ち込まれ、
[[憲章]] (>>14) に組み込まれて作業が進められることとなりました。

[REFS[
- [7] [CITE@en[Page Visibility]] ([TIME[2013-05-20 13:41:29 +09:00]] 版) <https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/PageVisibility/Overview.html>
- [8]
[9] [CITE@en[Page Visibility]] ([TIME[2013-05-14 19:49:45 +09:00]] 版) <http://www.w3c-test.org/webperf/specs/PageVisibility/>
-[1] [CITE@en[Page Visibility]]
( ([TIME[2011-07-20 07:16:55 +09:00]] 版))
<http://www.w3.org/TR/2011/WD-page-visibility-20110721/>
-[2] [CITE@en[Page Visibility]]
( ([TIME[2012-07-21 04:13:20 +09:00]] 版))
<http://www.w3.org/TR/2012/CR-page-visibility-20120726/>
- [5] [CITE@en[Page Visibility Results]] ([TIME[2013-02-08 02:31:23 +09:00]] 版) <http://www.w3.org/2013/02/pv-cr-report.html>
-[3] [CITE@en[Page Visibility]]
( ([TIME[2013-02-16 04:14:58 +09:00]] 版))
<http://www.w3.org/TR/2013/PR-page-visibility-20130219/>
- [4] [CITE@en[Page Visibility]] ([TIME[2013-05-11 05:27:55 +09:00]] 版) <http://www.w3.org/TR/2013/REC-page-visibility-20130514/>
]REFS]

[16] その後順調に進み (>>14 の予定より1年遅れていますが、 [[W3C]] でこの程度の遅れで済むのは例外的な方ですw)、
2013年2月に [[W3C]] [[勧告]]となっています。 >>5 によれば既に主要なすべての [[Webブラウザー]]にほぼ実装されています。

;; [17] 仕様策定も実装もこんなに順調に進むのは極めて例外的です・・・。

[18] なぜか一部の用語は [[HTML]] で規定されているものを使っているとみられますがリンクになっていません。
そのため定義が若干曖昧になっています。

[REFS[
- [25] [CITE@en[Page Visibility (Second Edition)]] ([TIME[2013-10-29 05:22:27 +09:00]] 版) <http://www.w3.org/TR/2013/REC-page-visibility-20131029/>
]REFS]

[26] >>25 で第2版が出版されていますが、差分は typo の修正だけです。

* テスト・ケース

[REFS[
- [6] [CITE@en[Web Performance Tests]] ([TIME[2013-05-15 04:49:45 +09:00]] 版) <http://w3c-test.org/webperf/tests/#pv>
]REFS]

[19] [CITE@en-US[Using the Page Visibility API - Web developer guide | MDN]]
( ([TIME[2013-05-14 14:19:03 +09:00]] 版))
<https://developer.mozilla.org/en-US/docs/Web/Guide/User_experience/Using_the_Page_Visibility_API>

[21] [CITE@en-US[webperf: Summary]]
( ([TIME[2013-10-13 12:39:21 +09:00]] 版))
<https://dvcs.w3.org/hg/webperf/>

[22] [CITE@en-US[webperf: File revisions]]
( ([TIME[2013-10-13 12:40:36 +09:00]] 版))
<https://dvcs.w3.org/hg/webperf/log/3bc3063dc9c3/specs/PageVisibility/Overview.html>

[23] [CITE@en-US[webperf: File revisions]]
( ([TIME[2013-10-13 12:42:05 +09:00]] 版))
<https://dvcs.w3.org/hg/webperf/log/tip/specs/PageVisibility2/Overview.html>

[24] [CITE@en[Page Visibility 2]]
( ([TIME[2013-10-13 12:42:50 +09:00]] 版))
<https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/PageVisibility2/Overview.html>

[27] [CITE@en[Page Visibility]]
( ([TIME[2014-05-23 05:42:51 +09:00]] 版))
<https://w3c.github.io/web-performance/specs/PageVisibility/Overview.html>

[FIG(quote)[
[FIGCAPTION[
[28] [CITE@en[Re: making page visibility a property of document instead of top  level browsing context]]
([[Michael van Ouwerkerk]] 著, [TIME[2014-01-27 23:32:51 +09:00]] 版)
<https://lists.w3.org/Archives/Public/public-web-perf/2014Jan/0047.html>
]FIGCAPTION]

> These APIs
> are disabled when the page is not visible: Geolocation, Vibration, Device
> Motion. The goal is to save battery and CPU.

]FIG]


[FIG(quote)[
[FIGCAPTION[
[29] [CITE@en[Safari 7.0]]
([TIME[2015-11-04 23:11:44 +09:00]] 版)
<https://developer.apple.com/library/safari/releasenotes/General/WhatsNewInSafari/Articles/Safari_7_0.html#//apple_ref/doc/uid/TP40014305-CH5-SW21>
]FIGCAPTION]

> A tab is eligible for napping when it meets any of the following conditions:
> The tab is in the background.
> The browser window is minimized.
> The browser window is in a desktop space not currently displayed.
> The browser window is occluded (covered) by another window or other object on the screen.
> The browser window is idle (has not been updated recently).
> The screen saver is on.
> Napping is inhibited when a tab is engaged in useful nonvisual tasks such as playing audio or dynamically loading content.
> 

]FIG]


[FIG(quote)[
[FIGCAPTION[
[30] [CITE@en[Safari 7.0]]
([TIME[2015-11-04 23:12:13 +09:00]] 版)
<https://developer.apple.com/library/safari/releasenotes/General/WhatsNewInSafari/Articles/Safari_7_0.html#//apple_ref/doc/uid/TP40014305-CH5-SW22>
]FIGCAPTION]

> A pair of new properties on the document object allow a page to determine when it is not visible to the user, so that it can avoid unnecessary processing and minimize power consumption:
> document.hidden: A Boolean flag telling whether the document is currently hidden.
> document.visibilityState: A string denoting the document’s current visibility state. Possible values are:
> "hidden": The document is currently hidden.
> "visible": The document is currently visible.
> "prerender": The document’s contents are currently being preloaded but not yet rendered. This occurs, for instance, when the user begins typing a URL into the browser’s location field: the browser attempts to predict the most likely completion of the partial URL as it is typed and begins preloading the predicted page so that it will be ready for immediate rendering when the Return key is pressed.
> A new event type, visibilitychange, notifies the application when the page’s visibility state has changed. The application can install an event listener that tests the values of the properties above and responds accordingly.

]FIG]

[32] [CITE@en[Called PV L2]]
( ([[plehegar]]著, [TIME[2016-06-22 02:58:28 +09:00]]))
<https://github.com/w3c/page-visibility/commit/00a00c3e17068e27d3d14d63019eed26770e2136>

[33] [CITE@en[Page Visibility 2]]
([TIME[2016-06-22 04:15:16 +09:00]])
<https://www.w3.org/TR/2016/WD-page-visibility-2-20160623/>

[34] [CITE[ブラウザがバックグラウンド回ったことを検知する - Qiita]]
( ([TIME[2016-08-22 17:56:45 +09:00]]))
<https://qiita.com/d2cs-kimura/items/b51ef73528fa66a35a9d>

[35] [CITE@en[Page Visibility Level 2]]
([TIME[2016-10-27 06:00:22 +09:00]])
<https://www.w3.org/TR/2016/WD-page-visibility-2-20161026/>

[36] [CITE@en[Wide review for Page Visibility 2]]
([[Philippe Le Hégaret]]著, [TIME[2016-10-27 06:08:13 +09:00]])
<https://lists.w3.org/Archives/Public/public-web-perf/2016Oct/0006.html>

[37] [CITE@en[Page Visibility Level 2]]
([TIME[2016-11-22 00:56:48 +09:00]])
<https://www.w3.org/TR/2016/CR-page-visibility-2-20161122/>

[38] [CITE@en[Call for Exclusions: Page Visibility Level 2]]
([[Xueyuan Jia]]著, [TIME[2016-11-22 18:13:44 +09:00]])
<https://lists.w3.org/Archives/Public/public-web-perf/2016Nov/0007.html>

[39] [CITE@en[Page Visibility Level 2]]
([TIME[2017-03-28 06:30:29 +09:00]])
<https://www.w3.org/TR/2017/CR-page-visibility-2-20170328/>

[40] [CITE@en[Call for Exclusions: Page Visibility Level 2]]
([[Xueyuan Jia]]著, [TIME[2017-03-29 16:21:22 +09:00]])
<https://lists.w3.org/Archives/Public/public-web-perf/2017Mar/0022.html>

[41] [CITE@en[Align with w3c/hr-time#47]]
([[plehegar]]著, [TIME[2017-05-05 03:34:45 +09:00]])
<https://github.com/w3c/page-visibility/commit/7972ab24110a8e20abc14d431e6d5ac86534c0b0>

[42] [CITE@en[Page Visibility Level 2]]
([TIME[2017-10-16 23:13:37 +09:00]])
<https://www.w3.org/TR/2017/PR-page-visibility-2-20171017/>

[43] [CITE@en[WICG/web-lifecycle]]
([TIME[2018-02-07 13:37:30 +09:00]])
<https://github.com/WICG/web-lifecycle>