W3C proposes hardware interface
The World Wide Web Consortium (W3C) draft for a "System Information API" specifies JavaScript functions for accessing the battery, CPU, sensors and other hardware characteristics of a device. For this purpose, the
window.navigator
object's SystemInfo
interface has to implement the get
, set
and watch
methods. set
can only be applied to some screen properties such as brightness and orientation, while all other hardware properties are marked as readonly
. watch
is used for monitoring readings, for example those of a heat sensor.
All the methods work asynchronously, and an application doesn't wait for their completion. Instead, the method calls an event handler. One of the W3C's examples alerts the user when the battery level is below 20% to illustrate the process:
navigator<span class="sh_symbol">.</span>system<span class="sh_symbol">.
</span>watch("Power",success,null,{lowThreshold:0.2});
function success(power) {
alert("Low battery level: "+power.level);
};
The document currently specifies access to the power supply, CPU, heat and other sensors, network, A/V codecs, storage systems such as hard disks, optical media and RAM as well as input and output channels of a device. Applications using the API must request permission for retrieving device data from the device owner. At least that's what proposed in the draft's "Security and Privacy" section.
See also:
- W3C proposes non-SQL database API, a report from The H.
(crve)