feat: warn when WebGPU or WebXR is used in an insecure context#8752
Merged
Conversation
Adds a small browser-only helper that calls Debug.warnOnce when window.isSecureContext is false at the moment WebGPU initialization or an XR session start is attempted. Browsers treat localhost as a secure context, so no warning fires on http://localhost — only on LAN/IP origins served over plain http where navigator.gpu / navigator.xr are unavailable.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds a small helper to warn (once) when WebGPU or WebXR is attempted in an insecure browser context (non-HTTPS, non-localhost), and wires it into the WebGPU and WebXR entry points to avoid warning on general engine initialization.
Changes:
- Added
warnInsecureContext(feature)helper that no-ops outside the browser and emits aDebug.warnOncewhenwindow.isSecureContextindicates an insecure origin. - Call the helper when WebGPU initialization fails due to missing
navigator.gpu. - Call the helper when XR start is attempted but XR is unavailable.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/platform/graphics/webgpu/webgpu-graphics-device.js | Emits an insecure-context warning when WebGPU isn’t available (before throwing). |
| src/framework/xr/xr-manager.js | Emits an insecure-context warning when XR start is attempted but XR is unavailable. |
| src/core/secure-context-warning.js | Adds the browser-only warnInsecureContext helper that logs via Debug.warnOnce. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Reword JSDoc to match actual behavior (warns on any insecure origin, not only LAN/IP). - Guard against window.isSecureContext being undefined in older / embedded runtimes by only warning when it is explicitly false.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
src/core/secure-context-warning.js, a small browser-only helper that callsDebug.warnOncewhenwindow.isSecureContextisfalse.WebgpuGraphicsDevice.initWebGpu()andXrManager.start()so the warning only fires when WebGPU or WebXR is actually attempted — not on every engine init.localhost/127.0.0.1/::1as secure contexts, so the warning is silent during normal local development. It surfaces on LAN/IP origins served over plainhttp, which is the case wherenavigator.gpu/navigator.xrare missing and the failure is otherwise mysterious.