{"id":13826207,"url":"https://github.com/immersive-web/webxr-polyfill","last_synced_at":"2025-11-13T22:34:01.430Z","repository":{"id":45758301,"uuid":"126254470","full_name":"immersive-web/webxr-polyfill","owner":"immersive-web","description":"Use the WebXR Device API today, providing fallbacks to native WebVR 1.1 and Cardboard","archived":false,"fork":false,"pushed_at":"2024-03-05T23:08:50.000Z","size":937,"stargazers_count":395,"open_issues_count":55,"forks_count":86,"subscribers_count":66,"default_branch":"main","last_synced_at":"2025-05-09T15:17:05.564Z","etag":null,"topics":["augmented-reality","polyfill","virtual-reality","vr","webvr","webxr","xr"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/immersive-web.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-21T23:52:46.000Z","updated_at":"2025-04-22T13:19:45.000Z","dependencies_parsed_at":"2024-06-18T13:39:47.375Z","dependency_job_id":"b3ccadd5-92f7-4714-9e66-dc0e0f1ec9d4","html_url":"https://github.com/immersive-web/webxr-polyfill","commit_stats":{"total_commits":132,"total_committers":20,"mean_commits":6.6,"dds":0.7878787878787878,"last_synced_commit":"fafd43da6ce49dd86d7cf8d94ff69a6cca593f9b"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/immersive-web%2Fwebxr-polyfill","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/immersive-web%2Fwebxr-polyfill/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/immersive-web%2Fwebxr-polyfill/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/immersive-web%2Fwebxr-polyfill/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/immersive-web","download_url":"https://codeload.github.com/immersive-web/webxr-polyfill/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254478186,"owners_count":22077675,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["augmented-reality","polyfill","virtual-reality","vr","webvr","webxr","xr"],"created_at":"2024-08-04T09:01:33.889Z","updated_at":"2025-11-13T22:34:01.357Z","avatar_url":"https://github.com/immersive-web.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Frameworks \u0026 Libraries"],"sub_categories":[],"readme":"# WebXR Polyfill\n\n[![Build Status](http://img.shields.io/travis/immersive-web/webxr-polyfill.svg?style=flat-square)](https://travis-ci.org/immersive-web/webxr-polyfill)\n[![Build Status](http://img.shields.io/npm/v/webxr-polyfill.svg?style=flat-square)](https://www.npmjs.org/package/webxr-polyfill)\n\nA JavaScript implementation of the [WebXR Device API][webxr-spec], as well as the [WebXR Gamepad Module][webxr-gamepad-module]. This polyfill allows developers to write against the latest specification, providing support when run on browsers that implement the [WebVR 1.1 spec][webvr-spec], or on mobile devices with no WebVR/WebXR support at all.\n\nThe polyfill reflects the stable version of the API which has shipped in multiple browsers.\n\n---\n\nIf you are writing code against the [WebVR 1.1 spec][webvr-spec], use [webvr-polyfill], which supports browsers with the 1.0 spec, or no implementation at all. It is recommended to write your code targeting the [WebXR Device API spec][webxr-spec] however and use this polyfill as browsers begin to implement the latest changes.\n\nThe minimal input controls currently supported by WebXR is polyfilled here as well, using the [Gamepad API][gamepad-api].\n\n## Setup\n\n### Installing\n\nDownload the build at [build/webxr-polyfill.js](build/webxr-polyfill.js) and include it as a script tag,\nor use a CDN. You can also use the minified file in the same location as `webxr-polyfill.min.js`.\n\n```html\n  \u003cscript src='webxr-polyfill.js'\u003e\u003c/script\u003e\n  \u003c!-- or use a link to a CDN --\u003e\n  \u003cscript src='https://cdn.jsdelivr.net/npm/webxr-polyfill@latest/build/webxr-polyfill.js'\u003e\u003c/script\u003e\n```\n\nOr if you're using a build tool like [browserify] or [webpack], install it via [npm].\n\n```\n$ npm install --save webxr-polyfill\n```\n\n### Building Locally\n\n```\n$ npm run build\n```\n\n### Using\n\nThe webxr-polyfill exposes a single constructor, `WebXRPolyfill` that takes an\nobject for configuration. See full configuration options at [API](#api).\n\nBe sure to instantiate the polyfill before calling any of your XR code! The\npolyfill needs to patch the API if it does not exist so your content code can\nassume that the WebXR API will just work.\n\nIf using script tags, a `WebXRPolyfill` global constructor will exist.\n\n```js\nvar polyfill = new WebXRPolyfill();\n```\n\nIn a modular ES6 world, import and instantiate the constructor similarly.\n\n```js\nimport WebXRPolyfill from 'webxr-polyfill';\nconst polyfill = new WebXRPolyfill();\n```\n\n## API\n\n### new WebXRPolyfill(config)\n\nTakes a `config` object with the following options:\n\n* `global`: What global should be used to find needed types. (default: `window` on browsers)\n* `webvr`: Whether or not there should be an attempt to fall back to a\n  WebVR 1.1 VRDisplay. (default: `true`).\n* `cardboard`: Whether or not there should be an attempt to fall back to a\n  JavaScript implementation of the WebXR API only on mobile. (default: `true`)\n* `cardboardConfig`: The configuration to be used for CardboardVRDisplay when used. Has no effect when `cardboard` is `false`, or another XRDevice is used. Possible configuration options can be found [here in the cardboard-vr-display repo](https://github.com/immersive-web/cardboard-vr-display/blob/master/src/options.js). (default: `null`)\n* `allowCardboardOnDesktop`: Whether or not to allow cardboard's stereoscopic rendering and pose via sensors on desktop. This is most likely only helpful for development and debugging. (default: `false`)\n\n## Browser Support\n\n**Development note: babel support is currently removed, handle definitively in [#63](https://github.com/immersive-web/webxr-polyfill/issues/63)**\n\nThere are 3 builds provided: [build/webxr-polyfill.js](build/webxr-polyfill.js), an ES5 transpiled build, its minified counterpart [build/webxr-polyfill.min.js](build/webxr-polyfill.min.js), and an untranspiled [ES Modules] version [build/webxr-polyfill.module.js](build/webxr-polyfill.module.js). If using the transpiled ES5 build, its up to developers to decide which browser features to polyfill based on their support, as no extra polyfills are included. Some browser features this library uses include:\n\n* TypedArrays\n* Object.assign\n* Promise\n* Symbol\n* Map\n* Array#includes\n\nCheck the [.babelrc](.babelrc) configuration and ensure the polyfill runs in whatever browsers you choose to support.\n\n## Polyfilling Rules\n\n* If `'xr' in navigator === false`:\n  * WebXR classes (e.g. `XRDevice`, `XRSession`) will be added to the global\n  * `navigator.xr` will be polyfilled.\n  * If the platform has a `VRDisplay` from the [WebVR 1.1 spec][webvr-spec] available:\n    * `navigator.xr.requestDevice()` will return a polyfilled `XRDevice` wrapping the `VRDisplay`.\n  * If the platform does not have a `VRDisplay`, `config.cardboard === true`, and on mobile:\n    * `navigator.xr.requestDevice()` will return a polyfilled `XRDevice` based on [CardboardVRDisplay].\n  * If `WebGLRenderingContext.prototype.setCompatibleXRDevice` is not a function:\n    * Polyfill all `WebGLRenderingContext.prototype.setCompatibleXRDevice` and a creation attribute\nfor `{ compatibleXrDevice }`.\n    * Polyfills `HTMLCanvasElement.prototype.getContext` to support a `xrpresent` type. Returns a polyfilled `XRPresentationContext` (via `CanvasRenderingContext2D` or `ImageBitmapRenderingContext` if supported) used for mirroring and magic window.\n* If `'xr' in navigator === true`, `config.cardboard === true` and on mobile:\n  * Overwrite `navigator.xr.requestDevice` so that a native `XRDevice` is returned if it exists, and if not, return a polyfilled `XRDevice` based on [CardboardVRDisplay].\n\nIn the future, when the WebXR API is implemented on a platform but inconsistent with spec (due to new spec changes or inconsistencies), the polyfill will attempt to patch these differences without overwriting the native behavior.\n\n## Not supported/Caveats\n\n* `XRWebGLLayer.framebufferScaleFactor`\n\n## License\n\nThis program is free software for both commercial and non-commercial use,\ndistributed under the [Apache 2.0 License](LICENSE).\n\n[webxr-spec]: https://immersive-web.github.io/webxr/\n[webvr-spec]: https://immersive-web.github.io/webvr/spec/1.1/\n[webvr-polyfill]: https://github.com/immersive-web/webvr-polyfill\n[npm]: https://www.npmjs.com\n[browserify]: http://browserify.org/\n[webpack]: https://webpack.github.io/\n[ES Modules]: https://jakearchibald.com/2017/es-modules-in-browsers/\n[CardboardVRDisplay]: https://immersive-web.github.io/cardboard-vr-display\n[gamepad-api]: https://developer.mozilla.org/en-US/docs/Web/API/Gamepad_API\n[webxr-gamepad-module]: https://immersive-web.github.io/webxr-gamepads-module/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimmersive-web%2Fwebxr-polyfill","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimmersive-web%2Fwebxr-polyfill","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimmersive-web%2Fwebxr-polyfill/lists"}