In JavaScript, the beforexrselect event fires before WebXR select events (select, selectstart, selectend) are dispatched (MDN). Use it on a DOM overlay to suppress XR world input while the user taps HTML UI.
Register a listener with addEventListener. Check readiness and browser support before you rely on this event.
Syntax
Listen for beforexrselect. Start with this line.
JavaScript
el.addEventListener("beforexrselect", fn)
Call
What it does
el.addEventListener("beforexrselect", fn)
Primary signature.
Built into the browser. Listen with el.addEventListener("beforexrselect", …) — no import required.
Library declarations
JavaScript
el.addEventListener("beforexrselect", fn)
Parameters
Parameter
Description
DOM overlay element
Required. Listen here so the event can bubble over UI
WebXR session
Required. Event fires during XR select toward the overlay
preventDefault()
Optional. Blocks following XR select events (MDN)
Return Value
Return Value
Description
*
Fires as an Element event (listener receives the Event object).
JavaScript Examples
Example 1 — Suppress XR Select on Overlay (MDN)
Cancel beforexrselect on the overlay so world select events do not fire.
Receive an XRSessionEvent. Same family as other session-state events.
Read event.session. The active XRSession for this select.
Inspect flags. Confirm cancelable before calling preventDefault().
Cancel when needed. Keep overlay UI from also driving the world.
Example 3 — Feature Detect
Check for the handler property before depending on the Experimental event.
JavaScript
const supported = "onbeforexrselect" in document.documentElement;
const hasXR = !!(navigator.xr);
console.log("onbeforexrselect:", supported);
console.log("navigator.xr:", hasXR);
if (!supported) {
console.log("Keep normal click handlers on the overlay");
}
onbeforexrselect: false
navigator.xr: false
Keep normal click handlers on the overlay
How It Works
Probe onbeforexrselect. Cheap signal for the event surface.
Also check navigator.xr. WebXR itself may be missing.
Keep click/pointer handlers. Overlay must work without XR.
Test on device. Limited availability means desktop checks are not enough.
Compatibility
Browser Support
Element.beforexrselect is marked Experimental and Limited availability on MDN (not Baseline). Logos use the shared browser-image-sprite.png sprite from this project.
✓ Experimental · Limited availability
Element beforexrselect
Fires before WebXR select events so a DOM overlay can suppress world input.
LimitedCheck compat
Google ChromeWebXR DOM overlays · check BCD
Partial
Mozilla FirefoxLimited / check BCD
Limited
Apple SafariLimited / check BCD
Limited
Microsoft EdgeFollow Chromium WebXR (check BCD)
Partial
OperaFollow Chromium behavior
Partial
Internet ExplorerNo WebXR / beforexrselect
Not supported
beforexrselectLimited availability
Bottom line: Use on Chromium WebXR DOM overlays, feature-detect, and keep HTML click handlers. See the MDN Element beforexrselect reference.
Frequently Asked Questions
It fires before WebXR select events (select, selectstart, selectend) are dispatched (MDN). Apps use it on a DOM overlay to suppress XR world input while the user interacts with HTML UI.
No. MDN marks it Experimental and Limited availability (not Baseline). It is part of the WebXR DOM Overlays Module. It is not Deprecated or Non-standard.
An XRSessionEvent (inherits from Event). It exposes a read-only session property referring to the XRSession.
Yes. MDN: beforexrselect bubbles, is cancelable, and is composed. Calling preventDefault() on the overlay (or a container) suppresses the following XR selectstart / select / selectend for that interaction.
Support is limited (not Baseline). Chromium-based browsers with WebXR DOM overlays are the typical path. Firefox and Safari generally lag. Always feature-detect and test on XR hardware.
overlay.addEventListener("beforexrselect", handler) or overlay.onbeforexrselect = handler. Listen on the DOM overlay element so bubbling can cover its UI tree.