Copyright © 2024 World Wide Web Consortium. W3C® liability, trademark and permissive document license rules apply.
This document specifies an API that allows web applications to request and be notified of changes of the posture of a device.
This section describes the status of this document at the time of its publication. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at https://www.w3.org/TR/.
Implementors need to be aware that this specification is extremely unstable. Implementors who are not taking part in the discussions will find the specification changing out from under them in incompatible ways. Vendors interested in implementing this specification before it eventually reaches the Candidate Recommendation phase should subscribe to the repository on GitHub and take part in the discussions.
This document was published by the Devices and Sensors Working Group as a Working Draft using the Recommendation track.
Publication as a Working Draft does not imply endorsement by W3C and its Members.
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.
This document was produced by a group operating under the W3C Patent Policy. W3C maintains a public list of any patent disclosures 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 Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.
This document is governed by the 03 November 2023 W3C Process Document.
The device posture is the physical position in which a device holds which may be derived from sensors in addition to the angle. New types of mobile devices are appearing that have some sort of capabilities that allow them to change their posture. The most common types of devices are the ones that can fold (their screen or around their screen), allowing them to physically alter their form factor. The main interest in knowing the posture of a device is to enable new user experiences with responsive design.
Among the described "folding" devices, there are mainly two different physical form factors: devices with a single flexible screen (seamless), and devices with two screens (with seam). They can both fold around a hinge, and the current specification applies to both types. It should be clarified as well that both seamless and (devices) with seam can be of different dimension ranging from mobile and tablets to laptop sizes. It should also be noted that different devices will have different default orientations (portrait or landscape), and that the fold might happen in a vertical or horizontal way.
From enhancing the usability of a website by avoiding the area of a fold, to enabling innovative use cases for the web, knowing the posture of a device can help developers tailor their content to different devices.
Content can be consumed and browsed even when the device is not flat, in which case the developer might want to provide a different layout for it depending on the posture state in which the device is being used.
The following internal slots are added to the Document
interface.
As it name implies, it will house the value of the current posture the
device is
Internal slot | Description |
---|---|
[[CurrentPosture]] | The current posture. |
WebIDL[SecureContext, Exposed=(Window)]
interface DevicePosture
: EventTarget {
readonly attribute DevicePostureType
type
;
attribute EventHandler onchange
;
};
enum DevicePostureType
{
"continuous
",
"folded
"
};
When getting the type attribute, the user agent MUST return the value
of this's relevant global object's associated Document's
internal slot [[CurrentPosture]]
.
The onchange
attribute is an event handler IDL attribute
for the onchange
event handler, whose event handler event type is "change".
This specification defines the following posture values:
Continuous posture: The continuous posture refers to a "flat" position. This is the default case for most devices not allowing different postures.
It includes devices with no folds, hinges or similar capabilities.
Due to the nature of hardware innovation, it also includes devices with dual, foldable, rollable or curved screens, as long as they are in a posture where the document is expected to be displayed with a flat layout.
Examples of these are:
In some cases, devices can run several apps and be in a physical posture other than flat, but as long as the browser does not span through several screens/sections, the corresponding posture is continuous.
Examples of these are:
In the API, the posture values are represented by the
DevicePostureType
enum values.
The device-posture
media feature represents,
via a CSS media query [MEDIAQ], the posture of the device. All
navigables reflect the posture of their
top-level traversable.
continuous
| folded
A user agent MUST reflect the applied posture of the web application via a CSS media query [MEDIAQ].
Every instance of Document
has an internal slot
[[CurrentPosture]]
, which should be initialized when the
document is created, otherwise they MUST be initialized the
first time they are accessed and before their value is read. The
user agent MUST run the device posture change steps with
the document and true to initialize it.
For a given document, the current posture is derived from the current hinge angle and the current screen orientation, and potentially other implementation-specific signals.
These tables are non-normative.
The values are approximations and might differ per device. For instance, a device might not yield exactly 180° when laying flat, but instead values ranging from 175° to 185°. Device makers SHOULD make sure that the physical device postures map correctly to the postures defined by this specification.
Some devices might also lack one or more of the postures due to physical constraints or device design, in which case the device SHOULD make sure that all combinations of angles and device orientation (which can be locked by [SCREEN-ORIENTATION] and host OS), as well as device specific signals, maps into one of the defined postures.
Posture | Angle value |
---|---|
continuous | < ~180° |
folded | ~180° |
The steps to calculate the device posture information of a
Document
document are as follows:
DevicePostureType
value determined in an
implementation-defined way based on the current hinge angle
value, current screen orientation, as well as potential
implementation-specific signals, according to the posture values table.
When the user agent determines that the screen(s)' fold angle, orientation or device-specific signals have changed for a top-level traversable, it MUST run the device posture change steps with the top-level traversable's active document.
The device posture change steps for a Document
document and an optional boolean disallowRecursion
(default false) are as follows:
[[CurrentPosture]]
, abort these steps.
[[CurrentPosture]]
to posture.
change
" at the
DevicePosture
object associated with document's relevant global object's associated Navigator
.
This specification defines the following page visibility change steps given visibility state and document:
From https://html.spec.whatwg.org/#update-the-visibility-state
It would be better if specification authors sent a pull request to add calls from here into their specifications directly, instead of using the page visibility change steps hook, to ensure well-defined cross-specification call order. As of the time of this writing the following specifications are known to have page visibility change steps, which will be run in an unspecified order: Device Posture API and Web NFC. [DEVICEPOSTURE] [WEBNFC]
The Device Posture API exposes a posture determined from the hinge angle value and other sensors.
Typical sensor readings are sent at a constant frequency to whomever is listening to its readings. However the fold angle only communicates its value when the hinge is manipulated by the user. Variations in the angle’s readings and posture calculation, as well as event dispatching frequency offer a possibility of fingerprinting to identify users. User agents may reduce this risk by limiting or coalescing events when exposing this information to web developers. Users don’t constantly adjust the angle, so the fold angle value is changing in bursts: the events may be dispatched at a very low frequency most of the time and fire at a high frequency when the device is being opened or closed. In order for the events to be dispatched, the content must be on the foreground and visible to the user. Because the API does not directly expose the raw angle values, but a more abstract posture with fewer possible states, fingerprinting possibilities are more limited.
If the same code using the API can be used simultaneously in different window contexts on the same device it may be possible for that code to correlate the user across those two contexts, creating unanticipated tracking mechanisms.
This section is non-normative.
This section is non-normative.
This section gives a high-level presentation of some of the mitigation strategies specified in the normative sections of this specification.
Posture value readings are explicitly flagged by the Secure Contexts specification as a high-value target for network attackers. Thus all interfaces defined by this specification or extension specifications are only available within a secure context.
Posture value readings are only available for active documents whose origin is the same origin-domain with the currently focused area document.
This is done in order to mitigate the risk of a skimming attack against the browsing context containing an element which has gained focus, for example when the user carries out an in-game purchase using a third party payment service from within an iframe.
Posture value change events are only fired for active documents whose visibility state is "visible", and polling the value while that is not the case, will return a stale value as the value is only updated while the visibility state is "visible" or just changed to "visible".
This section is non-normative.
This is a simple use case of the posture being printed on the console.
navigator.devicePosture.addEventListener("change", () => {
console.log(`The current posture is: ${navigator.devicePosture.type}!`);
})
The device is being used for a video call web service. It can be folded into the laptop posture to enable a hands-free when placed on a surface. The UA detects the posture and the UI is enhanced. Similar examples can be drafted for content to adapt to any posture. See the explainer for other key scenarios.
@media (device-posture: folded) and (vertical-viewport-segments: 1) {
body {
display: flex;
flex-flow: column nowrap;
}
.videocall-area, .videocall-controls {
flex: 1 1 env(viewport-segment-bottom 0 0);
}
}
As one of the valid device-posture values will always be true, you can use the following snippet to detect whether a user agent supports the media feature:
@media (device-posture) {
/*The browser supports device-posture feature*/
}
The following concepts and interfaces are defined in
[SCREEN-ORIENTATION]: current screen orientation as
represented by the OrientationType
enum.
The following is defined in [MEDIAQ]: Evaluating Media Features in a Boolean Context.
As well as sections marked as non-normative, all authoring guidelines, diagrams, examples, and notes in this specification are non-normative. Everything else in this specification is normative.
The key words MUST and SHOULD in this document are to be interpreted as described in BCP 14 [RFC2119] [RFC8174] when, and only when, they appear in all capitals, as shown here.
This specification defines conformance criteria for a single product: a user agent that implements the interfaces that it contains.
WebIDL[SecureContext, Exposed=(Window)]
partial interface Navigator {
[SameObject] readonly attribute DevicePosture
devicePosture
;
};
[SecureContext, Exposed=(Window)]
interface DevicePosture
: EventTarget {
readonly attribute DevicePostureType
type
;
attribute EventHandler onchange
;
};
enum DevicePostureType
{
"continuous
",
"folded
"
};
This section is non-normative.
We would like to offer our sincere thanks to Daniel Appelquist, Jo Balletti, Michael Blix, Alexis Menard and Laura Morinigo for their contributions to this work.
Referenced in:
Referenced in:
Referenced in:
Referenced in:
Referenced in: