coderef

Hit testLimited availability

The getHitTestResults() method of an XRFrame object helps place objects in an augmented reality session by finding where cast rays intersect with real-world geometry.

Not yet supported in all major browsers — check the table and provide a fallback.

Browser support

DesktopChrome
1–80Not supported
81+Supportedsince Apr 7, 2020
Current: 155
Edge
12–80Not supported
81+Supportedsince Apr 13, 2020
Current: 154
Firefox
✕Not supportedup to 157
Current: 157
Safari
✕Not supportedup to 27
Current: 27
MobileChrome Android
18–80Not supported
81+Supportedsince Apr 7, 2020
Current: 155
Firefox Android
✕Not supportedup to 157
Current: 157
Safari iOS
✕Not supportedup to 27
Current: 27

How to use

Not supported in Firefox, Safari, Firefox Android, Safari iOS. Use feature detection below and provide a fallback (or a polyfill) for those browsers.

Example

Full syntax and examples are on MDN: getHitTestResults.

Feature detection

JS · check before using
if ("XRHitTestResult" in globalThis) {
  // XRHitTestResult is available
} else {
  // load a polyfill or use a fallback
}

Sub-features

Support for each part of the feature (18). The overall table above shows when the whole feature works.

Sub-featureChromeEdgeFirefoxSafariChrome AndroidFirefox AndroidSafari iOS
XRFrame.getHitTestResults8181✕✕81✕✕
XRFrame.getHitTestResultsForTransientInput8181✕✕81✕✕
XRHitTestResult8181✕✕81✕✕
XRHitTestResult.getPose8181✕✕81✕✕
XRHitTestSource8181✕✕81✕✕
XRHitTestSource.cancel8181✕✕81✕✕
XRRay8181✕✕81✕✕
XRRay.XRRay8181✕✕81✕✕
XRRay.direction8181✕✕81✕✕
XRRay.matrix8181✕✕81✕✕
XRRay.origin8181✕✕81✕✕
XRSession.requestHitTestSource8181✕✕81✕✕
XRSession.requestHitTestSourceForTransientInput8181✕✕81✕✕
XRTransientInputHitTestResult8181✕✕81✕✕
XRTransientInputHitTestResult.inputSource8181✕✕81✕✕
XRTransientInputHitTestResult.results8181✕✕81✕✕
XRTransientInputHitTestSource8181✕✕81✕✕
XRTransientInputHitTestSource.cancel8181✕✕81✕✕