GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||
GeezerVison is showing w3c.github.io — Device Posture API This document specifies an API that allows web applications to request and be notified of changes of the posture of a device. This specification is implemented in Chromium-based browsers. WebKit and Mozilla have not yet published formal positions on this specification. 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. IntroductionThe 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. Extensions to the `Document` interfaceThe following internal slots are added to the {{Document}} interface.
Extensions to the `Navigator` interfaceThe [[HTML]] specification defines the {{Navigator}} interface, which this specification extends: [SecureContext, Exposed=(Window)]
partial interface Navigator {
[SameObject] readonly attribute DevicePosture devicePosture;
};
The DevicePosture interface
[SecureContext, Exposed=(Window)]
interface DevicePosture : EventTarget {
readonly attribute DevicePostureType type;
attribute EventHandler onchange;
};
enum DevicePostureType {
"continuous",
"folded"
};
The type attribute: Get current device postureWhen getting the type attribute, the user agent MUST return the value of [=this=]'s [=relevant global object=]'s [=associated Document=]'s internal slot {{Document/[[CurrentPosture]]}}. The onchange attribute: Handle posture changesThe {{onchange}} attribute is an event handler IDL attribute for the {{onchange}} [=event handler=], whose [=event handler event type=] is "change". Posture typesThis specification defines the following posture values:
In the API, the [=posture=] values are represented by the {{DevicePostureType}} enum values. Device Posture Media Queries
The
|
| Posture | Angle value |
|---|---|
| continuous | < ~180° |
| folded | ~180° |
The steps to calculate the device posture information of a {{Document}} |document:Document| are as follows:
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 [=navigable/active document=].
The device posture change steps for a {{Document}} document and an optional boolean disallowRecursion (default false) are as follows:
This specification defines the following [=page visibility change steps=] given |visibility state| and |document:Document|:
No new security considerations have been reported on this specification. However it is encouraged to look at the potential [[[#privacy-considerations]]] listed in this document.
This section is non-normative.
When this API is used simultaneously in different browsing contexts on the same device it may be possible to correlate the user across those two contexts, creating unanticipated tracking mechanisms. However, because the posture value is typically stable for a long time it could only be used to verify that two users are not the same, but it would not help to identify a given user given the fact that there are multiple types and models of foldable devices.
The added entropy is comparable to the pointer API which tells whether the user's primary input is touch-based or not. Such a primary input can change on devices where the keyboard can be removed/added or the tablet mode is activated/deactivated.
This theoretical attack is mitigated by [[[#data-minimization]]], [[[#user-attention]]] and [[[#user-mediated-action]]].
Cross-origin iframes have access to the posture through this API and therefore could use this information to identify users similarly to as mentioned in [[[#identifying-users-across-contexts]]]. The same mitigations apply.
Through iframes, a malicious actor could inject its own code to access the posture information and potentially use it to track users.
This theoretical attack is mitigated by [[[#data-minimization]]] as well as the fact that the posture value itself carry little valuable information and stays stable for long period of time.
The API exposes a high-level abstraction referred to as a posture that can be either "{{DevicePostureType/continuous}}" or "{{DevicePostureType/folded}}". Devices that do not support different postures default to "{{DevicePostureType/continuous}}". This means at most one bit of entropy is added to the fingerprint. At most, because revealing this one bit will require a significant, explicit physical action by the user to manipulate the physical posture of the device required to trigger a change.
While implementations can use a variety of low-level information to determine the most appropriate high-level posture, no low-level details are exposed through this API. Furthermore, there is no one-to-one mapping from any fine-grained low-level sensor reading to a high-level posture state. An implementation can use e.g. a hinge angle sensor, other sensors, information about whether a keyboard is docked, or whether the kickstand is deployed, or any combination of such information, to determine the most approriate posture for the given form factor. This abstraction ensures only a minimum amount of information necessary to implement the intended functionality is exposed adhering to the data minimization principles.
Posture value change events are only fired for each [=navigable/active document=] whose [=Document/visibility state=] is "visible" as explained in [=device posture change steps=], 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".
A user's significant and explicit physical action to modify the device posture is required for a posture change. Significant, because the action must cross the implementation-defined threshold per [=posture values table=], and explicit, because the underlying operating system adapts to posture changes similarly matching user's learned expectations for an outcome of such an action.
The Device Posture API pose a challenge to test authors, as fully exercising interface requires physical hardware devices. To address this challenge this document defines a [[WEBDRIVER2]] [=extension commands=] that allows users to control the reported device posture and simulate a real device.
To support the [=extension commands=] below and their integration with [[[#algorithms]]], [=top-level traversables=] must have the following internal slots:
| Internal slot | Description |
|---|---|
| [[\PostureOverride]] |
Overrides the [=current posture=] provided by the hardware.
Possible values:
|
| HTTP Method | [=extension command URI Template|URI Template=] |
|---|---|
| POST | /session/{session id}/deviceposture |
This [=extension command=] changes device posture to a specific {{DevicePostureType}}.
| Parameter name | Value type | Required |
|---|---|---|
| posture | String | yes |
The [=remote end steps=] are:
null.
| HTTP Method | [=extension command URI Template|URI Template=] |
|---|---|
| DELETE | /session/{session id}/deviceposture |
This [=extension command=] removes device posture override and returns device posture control back to hardware.
The [=remote end steps=] are:
null, return [=success=]
with data null.
null.
null.
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 experience 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: 2) {
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*/
}
For more information about media features in a boolean context
please refer to Evaluating Media Features in a Boolean Context.
This specification defines conformance criteria for a single product: a user agent that implements the interfaces that it contains.
We would like to thank Diego González for his major contributions to the specification as the founding editor, and for creating a visual identity to both this specification and the Devices and Sensors Working Group.
We would like to offer our sincere thanks to Daniel Appelquist, Jo Balletti, Michael Blix, Paul Grenier and Laura Morinigo for their contributions to this work.