The beforexrselect event fires before WebXR select / selectstart / selectend events. Learn how DOM overlays use it, why preventDefault() matters, how XRSessionEvent exposes session, and how to feature-detect support—with five examples and try-it labs.
01
Kind
Instance event
02
Type
XRSessionEvent
03
Cancelable
Yes (bubbles)
04
Status
Experimental
05
Module
WebXR DOM Overlays
06
Suppresses
XR select*
Fundamentals
Introduction
WebXR sessions can show a DOM overlay—HTML UI composited into the XR experience (menus, buttons, forms). When the user aims a controller or hand ray at that UI, you usually want normal DOM interaction, not a second “select” in the XR world.
beforexrselect is the bridge: it fires first, and if you cancel it on the overlay, the browser skips the XR selectstart / select / selectend sequence for that action. DOM pointer events still work separately.
💡
Beginner tip
Think of it as: “UI click coming—please do not also fire XR select.” Listen on the overlay root and call preventDefault().
Concept
Understanding beforexrselect
An instance event used with WebXR DOM overlays. It answers: “Is an XR select about to be generated for this interaction?”
Fires before WebXR select events are dispatched.
Bubbles, cancelable, composed (MDN).
XRSessionEvent — read event.session.
Purpose — suppress XR world input while using overlay UI.
Status — Experimental; Limited availability (not Baseline).
Foundation
📝 Syntax
Use the event name with addEventListener, or set the handler property:
MDN: the event bubbles, is cancelable, and is composed.
Sequence
🔁 Overlay vs XR Select
User triggers a primary XR action aimed at the DOM overlay.
Browser fires beforexrselect on the intersected overlay target (bubbles).
If you call preventDefault(), XR select* events are suppressed for that sequence.
DOM UI events (such as pointer events) can still occur independently.
That separation avoids “double input”: clicking a menu button should not also select an object in the XR scene.
Compare
⚖️ beforexrselect vs XR select
Topic
beforexrselect
XR select / selectstart / selectend
Timing
Before XR select events
The XR select sequence itself
Typical target
DOM overlay element
XRSession / input pipeline
Cancel effect
Can suppress the XR select sequence
N/A if suppressed upstream
Best for
Protecting HTML UI from XR picks
Selecting objects in the XR world
Cheat Sheet
⚡ Quick Reference
Goal
Code / note
Listen on overlay
overlay.addEventListener("beforexrselect", fn)
Handler property
overlay.onbeforexrselect = fn
Suppress XR select*
event.preventDefault()
Read session
event.session
Feature-detect
"onbeforexrselect" in window / element (weak) + WebXR session
MDN status
Experimental ยท Limited availability
Snapshot
🔍 At a Glance
Four facts to remember about beforexrselect.
Event type
XRSessionEvent
Has session
Cancelable
yes
Bubbles too
Suppresses
select*
XR input
Baseline?
no
Limited avail.
Hands-On
Examples Gallery
Examples follow MDN Element: beforexrselect event. Full XR sessions need a headset or emulator; labs still teach registration, cancel, and detection patterns.
📚 Getting Started
Register handlers on a DOM overlay root.
Example 1 — addEventListener("beforexrselect")
Attach a listener to the overlay container (MDN style).
Prefer addEventListener when you need multiple listeners or easy removal.
📈 Suppress, Session & Detect
Cancel XR select for UI hits, inspect session, and feature-detect.
Example 3 — Suppress XR Select with preventDefault()
MDN pattern: cancel on the overlay so XR select events do not fire for that UI interaction.
JavaScript
document
.getElementById("xr-overlay")
.addEventListener("beforexrselect", (ev) => ev.preventDefault());
// Effect (supporting browsers, during XR + DOM overlay):
// selectstart / select / selectend are not dispatched for this action.
// DOM UI interaction can continue without duplicate XR world input.
beforexrselect is Experimental and not Baseline on MDN. Logos use the shared browser-image-sprite.png sprite from this project. Expect Chromium-family support for WebXR DOM overlays; Firefox and Safari generally lack this event.
✓ Experimental · Limited availability
Element beforexrselect
Use with WebXR DOM overlays to suppress XR select* while interacting with HTML UI. Always feature-detect and test on device.
LimitedNot Baseline
Google Chrome83+ · WebXR DOM overlays
Supported
Mozilla FirefoxNo beforexrselect support
Unavailable
Apple SafariNo beforexrselect support
Unavailable
Microsoft Edge83+ Chromium · WebXR overlays
Supported
Opera69+ · Chromium-based
Supported
Internet ExplorerNo WebXR / beforexrselect
Unavailable
beforexrselectLimited
Bottom line: Listen on the DOM overlay, call preventDefault() to protect UI, and keep a fallback for browsers without WebXR overlays.
Wrap Up
Conclusion
beforexrselect lets WebXR DOM overlays claim a controller or hand action for HTML UI before XR select events fire. Cancel it on the overlay root, keep an eye on limited browser support, and always test in a real immersive session.
Prefer addEventListener("beforexrselect", ...) on the overlay root
Call preventDefault() when UI should own the interaction
Feature-detect WebXR + event support
Test on real XR hardware or a trusted emulator
Keep a non-XR / non-overlay UI fallback
❌ Don’t
Assume Firefox or Safari support today
Expect canceling XR select to stop all DOM pointer events
Ship without checking Limited availability on MDN
Confuse this with ordinary mouse select / text selection
Overwrite onbeforexrselect if you need multiple listeners
Summary
Key Takeaways
Knowledge Unlocked
Five things to remember about beforexrselect
Cancel on the DOM overlay so XR select* does not fight your HTML UI.
5
Core concepts
🎲01
Before XR select
overlay gate
Event
🧪02
Experimental
limited avail.
Status
🛑03
Cancelable
preventDefault
API
📄04
XRSessionEvent
event.session
Type
🚀05
Suppress select*
protect UI
Goal
❓ Frequently Asked Questions
It fires before WebXR select events (select, selectstart, selectend) are dispatched. 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 states 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. Chromium-based browsers (Chrome / Edge from around 83+) implement it. Firefox and Safari generally do not. 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.
Did you know?
Cancelling beforexrselect only suppresses the WebXR select sequence. The same user action can still produce ordinary DOM events (for example pointerdown), and those may arrive before or after beforexrselect—they are not locked together.