visit
Deprecated
This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.
Note: WebVR API is replaced by . WebVR was never ratified as a standard, was implemented and enabled by default in very few browsers and supported a small number of devices.
WebVR provides support for exposing virtual reality devices — for example, head-mounted displays like the Oculus Rift or HTC Vive — to web apps, enabling developers to translate position and movement information from the display into movement around a 3D scene. This has numerous, interesting applications, from virtual product tours and interactive training apps to immersive first-person games.
Any VR devices attached to your computer will be returned by the method; each one will be represented by a object.
is the central interface in the WebVR API — via its properties and methods you can access functionality to:
A typical (simple) WebVR app would work like so:
In addition, WebVR 1.1 adds a number of events on the object to allow JavaScript to respond to changes to the status of the display.
Note: You can find a lot more out about how the API works in our and articles.
Using controllers: Combining WebVR with the Gamepad API
Many WebVR hardware setups feature controllers that go along with the headset. These can be used in WebVR apps via the , and specifically the that adds API features for accessing , , and more.
Note: Our article explains the basics of how to use VR controllers with WebVR apps.
Represents any VR device supported by this API. It includes generic information such as device IDs and descriptions, as well as methods for
starting to present a VR scene, retrieving eye parameters and display
capabilities, and other important functionality.
Describes the capabilities of a — it's features can be used to perform VR device capability tests, for example can it return position information.
Represents the event object of WebVR-related events (see the listed below).
Represents all the information needed to render a single frame of a VR scene; constructed by .
Represents the position state at a given timestamp (which includes orientation, position, velocity, and acceleration.)
Provides access to all the information required to correctly render
a scene for each given eye, including field of view information.
Represents a field of view defined by 4 different degree values describing the view from a center point.
Represents a layer to be presented in a .
Represents the values describing the the stage area for devices that support room-scale experiences.
Extensions to other interfaces
The WebVR API extends the following APIs, adding the listed features.
Gamepad
Returns the of the associated — the VRDisplay that the gamepad is controlling the displayed scene of.
Navigator
Returns an array containing every object that is currently presenting ( is
true
).Returns a promise that resolves to an array of objects representing any available VR displays connected to the computer.
Window events
Represents an event handler that will run when the presenting state of a VR display changes — i.e. goes from presenting to not presenting or vice versa (when the event fires).
Represents an event handler that will run when a compatible VR display has been connected to the computer (when the event fires).
Represents an event handler that will run when a compatible VR display has been disconnected from the computer (when the event fires).
Represents an event handler that will run when a display is able to be presented to (when the event fires), for example if an HMD has been moved to bring it out of standby, or woken up by being put on.
Represents an event handler that will run when a display can no longer be presented to (when the event fires), for example if an HMD has gone into standby or sleep mode due to a period of inactivity.
Represents an event handler that will run when presentation to a display has been paused for some reason by the browser, OS, or VR hardware (when the event fires) — for example, while the user is interacting with a system menu or browser, to prevent tracking or loss of experience.
Represents an event handler that will run when presentation to a display has resumed after being blurred (when the event fires).
You can find a number of examples at these locations:
Navigator.getVRDisplays