Another abandoned server code base... this is kind of an ancestor of taskrambler.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

454 lines
23 KiB

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta content="text/html; charset=utf-8" http-equiv="content-type">
<title>Page Visibility</title>
<style type="text/css">
pre.idl { border:solid thin; background:#eee; color:#000; padding:0.5em }
pre.idl :link, pre.idl :visited { color:inherit; background:transparent }
pre code { color:inherit; background:transparent }
div.example { margin-left:1em; padding-left:1em; border-left:double; color:#222; background:#fcfcfc }
.note { margin-left:2em; font-weight:bold; font-style:italic; color:#008000 }
p.note::before { content:"Note: " }
.XXX { padding:.5em; border:solid #f00 }
p.XXX::before { content:"Issue: " }
dl.switch { padding-left:2em }
dl.switch > dt { text-indent:-1.5em }
dl.switch > dt:before { content:'\21AA'; padding:0 0.5em 0 0; display:inline-block; width:1em; text-align:right; line-height:0.5em }
dl.domintro { color: green; margin: 2em 0 2em 2em; padding: 0.5em 1em; border: none; background: #DDFFDD; }
dl.domintro dt, dl.domintro dt * { color: black; text-decoration: none; }
dl.domintro dd { margin: 0.5em 0 1em 2em; padding: 0; }
dl.domintro dd p { margin: 0.5em 0; }
dl.domintro:before { display: table; margin: -1em -0.5em -0.5em auto; width: auto; content: 'This box is non-normative. Implementation requirements are given below this box.'; color: red; border: solid 2px; background: white; padding: 0 0.25em; }
em.ct { text-transform:lowercase; font-variant:small-caps; font-style:normal }
dfn { font-weight:bold; font-style:normal }
code { color:orangered }
code :link, code :visited { color:inherit }
hr:not(.top) { display:block; background:none; border:none; padding:0; margin:2em 0; height:auto }
table { border-collapse:collapse; border-style:hidden hidden none hidden }
table thead { border-bottom:solid }
table tbody th:first-child { border-left:solid }
table td, table th { border-left:solid; border-right:solid; border-bottom:solid thin; vertical-align:top; padding:0.2em }
.auto-style1 {
background-color: #FFFFFF;
}
</style>
<link href="http://www.w3.org/StyleSheets/TR/W3C-WD.css" rel="stylesheet" type="text/css">
</head>
<body class="wd">
<div class="head">
<p>
<a href="http://www.w3.org/"><img alt="W3C" src="http://www.w3.org/Icons/w3c_home" height="48" width="72"></a>
</p>
<h1>Page Visibility</h1>
<h2 class="no-num no-toc" id="working-draft-july-21-2011">W3C Working Draft 21 July 2011</h2>
<dl>
<dt>This version:</dt>
<dd><a
href="http://www.w3.org/TR/2011/WD-page-visibility-20110721/">http://www.w3.org/TR/2011/WD-page-visibility-20110721/</a></dd>
<dt>Latest version:</dt>
<dd><a
href="http://www.w3.org/TR/page-visibility/">http://www.w3.org/TR/page-visibility/</a></dd>
<dt>Latest Editor's Draft:</dt>
<dd><a
href="https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/PageVisibility/Overview.html">https://dvcs.w3.org/hg/webperf/raw-file/tip/specs/PageVisibility/Overview.html</a></dd>
<dt>Previous version:</dt>
<dd><a
href="http://www.w3.org/TR/2011/WD-page-visibility-20110602/">http://www.w3.org/TR/2011/WD-page-visibility-20110602/</a></dd>
<dt>Editors:</dt>
<dd class="vcard"><span class="fn">Jatinder Mann</span> (<span
class="org">Microsoft Corp.</span>) &lt;<a
class="email" href="mailto:jmann@microsoft.com">jmann@microsoft.com</a>&gt; </dd>
<dd class="vcard"><span class="fn">Arvind Jain</span> (<span
class="org">Google Inc.</span>) &lt;<a
class="email" href="mailto:arvind@google.com">arvind@google.com</a>&gt; </dd>
</dl>
<p class=copyright><a
href="http://www.w3.org/Consortium/Legal/ipr-notice#Copyright">Copyright</a>
&copy; 2011 <a href="http://www.w3.org/"><acronym title="World Wide Web
Consortium">W3C</acronym></a><sup>&reg;</sup> (<a
href="http://www.csail.mit.edu/"><acronym title="Massachusetts Institute
of Technology">MIT</acronym></a>, <a
href="http://www.ercim.eu/"><acronym title="European Research Consortium
for Informatics and Mathematics">ERCIM</acronym></a>, <a
href="http://www.keio.ac.jp/">Keio</a>), All Rights Reserved. W3C <a
href="http://www.w3.org/Consortium/Legal/ipr-notice#Legal_Disclaimer">liability</a>,
<a
href="http://www.w3.org/Consortium/Legal/ipr-notice#W3C_Trademarks">trademark</a>
and <a
href="http://www.w3.org/Consortium/Legal/copyright-documents">document
use</a> rules apply.</p>
<hr class='top'>
</div>
<h2 class="no-num no-toc" id="abstract">Abstract</h2>
<p>This specification defines a means for site developers to programmatically determine
the current visibility state of the page in order to develop power and CPU efficient web applications.
</p>
<h2 class="no-num no-toc" id="status-of-this-document">Status of this
document</h2>
<p><em>This section describes the status of this document at the time of
its publication. Other documents may supersede this document. A list of
current W3C publications and the latest revision of this technical report
can be found in the <a href="http://www.w3.org/TR/">W3C technical reports
index</a> at http://www.w3.org/TR/.</em></p>
<p>This is the <strong>Last Call</strong> Working Draft of the Page Visibility specification. Please send comments
to <a href="mailto:public-web-perf@w3.org?subject=[PageVisibility]%20">public-web-perf@w3.org</a>
(<a href="http://lists.w3.org/Archives/Public/public-web-perf/">archived</a>)
with <samp>[PageVisibility]</samp> at the start of the subject line <strong>by 18 August 2011</strong>.</p>
<p>
A <a href='diff.html'>diff document</a> with the previous draft is available.
</p>
<p>This document is produced by
the <a href="http://www.w3.org/2010/webperf/">Web Performance</a>
Working Group. The Web Performance Working Group is part of
the <a href="http://www.w3.org/2006/rwc/Activity">Rich Web Clients
Activity</a> in the
W3C <a href="http://www.w3.org/Interaction/">Interaction
Domain</a>.
<p>Publication as a Working Draft does not imply endorsement by the
W3C Membership. This is a draft document and may be updated, replaced
or obsoleted by other documents at any time. It is inappropriate to
cite this document as other than work in progress. </p>
<p>This document was produced by a group operating under
the <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/">5
February 2004 W3C Patent Policy</a>. W3C maintains
a <a href="http://www.w3.org/2004/01/pp-impl/45211/status"
rel="disclosure">public list of any patent disclosures</a> made in
connection with the deliverables of the group; that page also
includes instructions for disclosing a patent. An individual who
has actual knowledge of a patent which the individual believes
contains <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/#def-essential">Essential
Claim(s)</a> must disclose the information in accordance
with <a href="http://www.w3.org/Consortium/Patent-Policy-20040205/#sec-Disclosure">section
6 of the W3C Patent Policy</a>.</p>
<p>
Implementers should be aware that this document is not stable. Implementers who are not taking part in the discussions are likely to find the specification changing out from under them in incompatible ways. Vendors interested in implementing this document before it eventually reaches the Candidate Recommendation stage should join the aforementioned mailing lists and take part in the discussions.</p>
<h2 class="no-num no-toc" id="table-of-contents">Table of Contents</h2>
<!--begin-toc-->
<ol class="toc">
<li><a href="#introduction"><span class="secno">1
</span>Introduction</a></li>
<li><a href="#conformance-requirements"><span class="secno">2
</span>Conformance requirements</a></li>
<li><a href="#terminology"><span class="secno">3 </span>Terminology</a></li>
<li><a href="#sec-page-visibility"><span class="secno">4 </span>Page Visibility</a>
<ol class="toc">
<li><a href="#sec-page-visibility-introduction"><span class="secno">4.1 </span>Introduction</a></li>
<li><a href="#sec-document-visibility-interface"><span class="secno">4.2 </span>The <code>DocumentVisibility</code> interface</a></li>
<li><a href="#sec-visibilitychange-event"><span class="secno">4.3 </span>The <code>visibilitychange</code> event</a></li>
<li><a href="#sec-vendor-prefix"><span class="secno">4.4 </span>Vendor Prefixes</a></li>
</ol>
</li>
<li><a href="#references"><span class="secno">5 </span>References</a></li>
<li><a class="no-num" href="#acknowledgements">Acknowledgements</a></li>
</ol>
<!--end-toc-->
<h2 id="introduction"><span class="secno">1 </span>Introduction</h2>
<p>This section is non-normative.</p>
<p>
The Page Visibility specification defines a means for site developers to
programmatically determine the current visibility of a document and be notified
of visibility changes. Without knowing the visibility state of a page, a web developer
must design the webpage as if it is always visible. This not only results in higher
machine resource utilization, but it prevents web developers from making runtime
decisions based on whether the webpage is visible to the user. Designing web pages with knowledge
of the page visibility will allow for improved user experiences and power efficient sites.</p>
<p>With this interface, web applications may chose to alter behavior based on whether they are
visible to the user or not. For example, this interface can be used to scale back work when the page is no
longer visible. If a web based email client is visible, it may check the server for new mail every few seconds.
When hidden it might scale checking email to every few minutes. This interface can also be used to provide better runtime
user experience decisions not related to power management. For example, a puzzle game could be paused when the user
no longer has the game visible. Further, this interface can be used by advertisers to not charge for ads that are
not visible to users.</p>
<div class="example">
<p>For example, the following Javascript shows a theoretical web based email client checking for new emails every second without knowledge of
the Page Visibility:</p>
<pre>
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;script&gt;
var timer = 0;
var PERIOD = 1000;
function onLoad() {
timer = setInterval(checkEmail, PERIOD);
}
function checkEmail() {
// Check server for new emails
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body onload="onLoad()"&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
</div>
<p>The script will always check for emails every second, even if the user
is not actively viewing the page because it is not visible. This is an example of poor resource management.</p>
<p>Using the <a href="#pv-document-visibility-interface">DocumentVisibility</a>
interface, the page will be able to throttle checking email to every minute when the
page is no longer visible.</p>
<div class="example">
<p>The following script show the theoretical web based email client checking for new emails every second when visible and every minute when not visible:</p>
<pre>
&lt;!DOCTYPE html&gt;
&lt;html&gt;
&lt;head&gt;
&lt;script&gt;
var timer = 0;
var PERIOD_VISIBLE = 1000;
var PERIOD_NOT_VISIBLE = 60000;
function onLoad() {
timer = setInterval(checkEmail, (document.hidden) ? PERIOD_NOT_VISIBLE : PERIOD_VISIBLE);
if(document.addEventListener) document.addEventListener("visibilitychange", visibilityChanged);
}
function visibilityChanged() {
clearTimeout(timer);
timer = setInterval(checkEmail, (document.hidden) ? PERIOD_NOT_VISIBLE : PERIOD_VISIBLE);
}
function checkEmail() {
// Check server for new emails
}
&lt;/script&gt;
&lt;/head&gt;
&lt;body onload="onLoad()"&gt;
&lt;/body&gt;
&lt;/html&gt;</pre>
</div>
<h2 id="conformance-requirements"><span class="secno">2 </span>Conformance
requirements</h2>
<p>All diagrams, examples, and notes in this specification are non-normative,
as are all sections explicitly marked non-normative. Everything else in this
specification is normative. </p>
<p>The key words "MUST", "MUST NOT", "REQUIRED", "SHOULD", "SHOULD NOT",
"RECOMMENDED", "MAY", and "OPTIONAL" in the normative parts of this document
are to be interpreted as described in <a href="#rfc2119">RFC 2119</a>.
For readability, these words do not appear in all uppercase letters in this specification.</p>
<p>Requirements phrased in the imperative as part of algorithms (such as
"strip any leading space characters" or "return false and abort these steps")
are to be interpreted with the meaning of the key word ("must", "should",
"may", etc) used in introducing the algorithm. </p>
<p>Some conformance requirements are phrased as requirements on attributes,
methods or objects. Such requirements are to be interpreted as requirements
on user agents. </p>
<p>Conformance requirements phrased as algorithms or specific steps may be
implemented in any manner, so long as the end result is equivalent. (In
particular, the algorithms defined in this specification are intended to be
easy to follow, and not intended to be performant.) </p>
<h2 id="terminology"><span class="secno">3 </span>Terminology</h2>
<p>The construction "a <code title="">Foo</code> object", where <code
title="">Foo</code> is actually an interface, is sometimes used instead of
the more accurate "an object implementing the interface <code
title="">Foo</code>". </p>
<p>The term DOM is used to refer to the API set made available to scripts in
Web applications, and does not necessarily imply the existence of an actual
<code>Document</code> object or of any other <code>Node</code> objects as
defined in the <a href="#DOM3Core">DOM Core specifications</a>.</p>
<p>A DOM attribute is said to be <em>getting</em> when its value is being
retrieved (such as by author script), and is said to be <em>setting</em> when
a new value is assigned to it. </p>
<p>The term "JavaScript" is used to refer to
<a href="#ECMA262">ECMA-262</a>,
rather than the official term ECMAScript, since the term JavaScript is more widely known.</p>
<h2 id="sec-page-visibility"><span class="secno">4 <span class="auto-style1">Page Visibility</span></span></h2>
<h3 id="sec-page-visibility-introduction"><span class="secno">4.1 </span>Introduction</h3>
<p>This section is non-normative</p>
<p>This specification introduces an interface that provides Web applications
with the means to programmatically determine the current visibility of a page
and be notified of visibility changes.</p>
<h3 id="sec-document-visibility-interface"><span class="secno">4.2 </span>The <code>DocumentVisibility</code> interface</h3>
<pre class="idl">
[NoInterfaceObject]
interface <dfn id="pv-document-visibility-interface">DocumentVisibility</dfn> {
const DOMString <a href="#pv-page-hidden" title="pagehidden">PAGE_HIDDEN</a> = "hidden";
const DOMString <a href="#pv-page-visible" title="pagevisible">PAGE_VISIBLE</a> = "visible";
const DOMString <a href="#pv-page-preview" title="pagepreview">PAGE_PREVIEW</a> = "preview";
readonly attribute boolean <a href="#pv-hidden" title="isHidden">hidden</a>;
readonly attribute unsigned short <a href="#pv-visibility-state" title="visibilitystate">visibilityState</a>;
};
Document implements DocumentVisibility;
</pre>
<h4><code><dfn id="pv-hidden">hidden</dfn></code> attribute</h4>
<p>This attribute returns true if the <a href="http://www.w3.org/TR/DOM-Level-3-Core/core.html#i-Document">Document </a> contained by the
<a href="http://dev.w3.org/html5/spec/Overview.html#top-level-browsing-context">top level browsing context</a> (root window in the browser's viewport)
is not visible at all. This attribute returns false if the <a href="http://www.w3.org/TR/DOM-Level-3-Core/core.html#i-Document">Document </a> contained by the
<a href="http://dev.w3.org/html5/spec/Overview.html#top-level-browsing-context">top level browsing context</a>
is at least partially visible on at least one screen.
</p>
<p>To accommodate accessibility tools that are typically full screen but still show a
view of the page, when applicable, this attribute may return false when the User Agent
is not minimized but is fully obscured by other applications.</p>
<p>As examples, the attribute returns true when: </p>
<ul>
<li>The User Agent is minimized.</li>
<li>The User Agent is not minimized, but the page is on a background tab.</li>
<li>The Operating System lock screen is shown.</li>
<li>The User Agent is minimized and a preview is shown.</li>
</ul>
<p>Likewise, as examples, the attribute returns false when:</p>
<ul>
<li>The User Agent is not minimized and the page is on a foreground tab.</li>
<li>The User Agent is fully obscured by an Accessibility Tool, like a magnifier, but
a view of the page is shown.</li>
</ul>
<h4><code><dfn id="pv-visibility-state">visibilityState</dfn></code> attribute</h4>
<h5><code><dfn id="pv-page-hidden">document.PAGE_HIDDEN</dfn></code></h5>
<p>This attribute must return <code>document.PAGE_HIDDEN</code> if the <a href="http://www.w3.org/TR/DOM-Level-3-Core/core.html#i-Document">Document </a>contained by the
<a href="http://dev.w3.org/html5/spec/Overview.html#top-level-browsing-context">top level browsing context</a>
is not visible at all on any screen.</p>
<p>To accommodate accessibility tools that are typically full screen but still
show a view of the page, when applicable, this constant may not be returned
when the User Agent is not minimized but is fully obscured by other applications.</p>
<p>For example, the following cases would return <code>document.PAGE_HIDDEN</code>:</p>
<ul>
<li>The User Agent is minimized.</li>
<li>The User Agent is not minimized, but the page is on a background tab.</li>
<li>The Operating System lock screen is shown.</li>
</ul>
<h5><code><dfn id="pv-page-visible">document.PAGE_VISIBLE</dfn></code></h5>
<p>This attribute must return <code>document.PAGE_VISIBLE</code> if the <a href="http://www.w3.org/TR/DOM-Level-3-Core/core.html#i-Document">Document </a>contained by the
<a href="http://dev.w3.org/html5/spec/Overview.html#top-level-browsing-context">top level browsing context</a>
is at least partially visible at on at least one screen. This is the same condition under which the <code><dfn>hidden</dfn></code> attribute
is set to false.</p>
<p>This constant is not returned if the <a href="http://www.w3.org/TR/DOM-Level-3-Core/core.html#i-Document">Document</a> contained by the
<a href="http://dev.w3.org/html5/spec/Overview.html#top-level-browsing-context">top level browsing context</a> is not
visible, however, a preview of the <a href="http://www.w3.org/TR/DOM-Level-3-Core/core.html#i-Document">Document</a> is
visible.</p>
<p>To accommodate accessibility tools that are typically full screen but still show a
view of the page, when applicable, this constant may be returned when the User Agent
is not minimized but is fully obscured by other applications.</p>
<h5><code><dfn id="pv-page-preview">document.PAGE_PREVIEW</dfn></code></h5>
<p>This attribute is optional. This attribute may return <code>document.PAGE_PREVIEW</code> if the
<a href="http://www.w3.org/TR/DOM-Level-3-Core/core.html#i-Document">Document </a>contained by the
<a href="http://dev.w3.org/html5/spec/Overview.html#top-level-browsing-context">top level browsing context</a>
is not visible at all and a preview of the the <a href="http://www.w3.org/TR/DOM-Level-3-Core/core.html#i-Document">Document</a> is
visible.</p>
<h3 id="sec-visibilitychange-event"><span class="secno">4.3 </span>
The <code><dfn id="pv-visibility-change-event">visibilitychange</dfn></code> event</h3>
<p>The visibilitychange event is fired any time a change is made to the
<code>document.visibilityState</code> attribute. This event can only be registered using
addEventListener on document. This event will get fired on the first change in
<code>document.visibilityState</code> after registration; it will not get fired on
registration.</p>
<h3 id="sec-vendor-prefix"><span class="secno">4.4 </span>Vendor Prefixes</h3>
<p>If a vendor-specific proprietary user agent extension to the <a href="#pv-visibility-state"><code>visibilityState</code></a> attribute
is needed for an experimental visibility state, vendors must use the following convention:</p>
<p><code>const DOMString [VENDORPREFIX]_PAGE_[NAME] = "[vendorprefix]-[name]";</code></p>
<p>Where,</p>
<ul>
<li><code>[VENDORPREFIX]</code> is a capitalized name that identifies the vendor,</li>
<li><code>[NAME]</code> is a capitalized name given to the visibility state,</li>
<li><code>[vendorprefix]</code> is a non-capitalized name that identifies the vendor,</li>
<li><code>[name]</code> is a non-capitalized name given to the visibility state.</li>
</ul>
<h2 id="references"><span class="secno">5 </span>References</h2>
<dl>
<dt><a name="rfc2119" id="rfc2119">[IETF RFC 2119]</a></dt>
<dd>
<cite><a href="http://www.ietf.org/rfc/rfc2119.txt">Key words for use in RFCs to Indicate Requirement Levels</a></cite>,
Scott Bradner, Author. Internet Engineering Task Force, March 1997. Available at
<a href="http://www.ietf.org/rfc/rfc2119.txt">http://www.ietf.org/rfc/rfc2119.txt</a>.
</dd>
<dt>[<a name="DOM3Core" id='DOM3Core'>DOM Level 3 Core</a>]</dt>
<dd>
<cite><a href="http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/">Document Object Model Level 3 Core
Specification</a></cite>, A. Le Hors, et al., Editors. World
Wide Web Consortium, 7 April 2004. This version of the Document
Object Model Level 3 Core Recommendation is
http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407. The <a class="normative" href="http://www.w3.org/TR/DOM-Level-3-Core/">latest version of
DOM Level 3 Core</a> is available at
http://www.w3.org/TR/DOM-Level-3-Core.
</dd>
<dt>[<a name="ECMA262" id="ECMA262">ECMA-262</a>]</dt>
<dd>
<cite><a href='http://www.ecma-international.org/publications/standards/Ecma-262.htm'>ECMAScript Language Specification</a></cite>, 5<sup>th</sup>
Edition. ECMA International, Standard
ECMA-262, December 2009. This version of the ECMAScript
Language is available from <a href='http://www.ecma-international.org/publications/standards/Ecma-262.htm'>http://www.ecma-international.org/publications/standards/Ecma-262.htm</a>.
</dd>
<dt>[<a name="HTML5" id="HTML5">HTML5</a>]</dt>
<dd><cite><a href='http://www.w3.org/TR/html5/'>HTML5</a></cite>, Ian Hickson, Editor. World Wide Web Consortium, May 2011. This version of the HTML5 is available from <a href='http://www.w3.org/TR/html5/'>http://www.w3.org/TR/html5/</a>. The <a href='http://dev.w3.org/html5/spec/'>latest editor's draft</a> is available at http://dev.w3.org/html5/spec/.</dd>
</dl>
<h2 class="no-num" id="acknowledgements">Acknowledgements</h2>
<p>We would like to sincerely thank Karen Anderson, Nic Jansma, Alex Komoroske, Cameron McCormack, James Robinson,
Jonas Sicking, Kyle Simpson, Jason Weber, and Boris Zbarsky to acknowledge their contributions to this work.</p>
</body>
</html>