Skip to content

feat: warn when WebGPU or WebXR is used in an insecure context#8752

Merged
mvaligursky merged 2 commits into
mainfrom
feat/secure-context-warning
May 20, 2026
Merged

feat: warn when WebGPU or WebXR is used in an insecure context#8752
mvaligursky merged 2 commits into
mainfrom
feat/secure-context-warning

Conversation

@mvaligursky
Copy link
Copy Markdown
Contributor

@mvaligursky mvaligursky commented May 20, 2026

Summary

  • Adds src/core/secure-context-warning.js, a small browser-only helper that calls Debug.warnOnce when window.isSecureContext is false.
  • Wires it into WebgpuGraphicsDevice.initWebGpu() and XrManager.start() so the warning only fires when WebGPU or WebXR is actually attempted — not on every engine init.
  • Browsers treat localhost / 127.0.0.1 / ::1 as secure contexts, so the warning is silent during normal local development. It surfaces on LAN/IP origins served over plain http, which is the case where navigator.gpu / navigator.xr are missing and the failure is otherwise mysterious.
  • No-ops in Node (typeof window guard), so server-side / test usage stays silent.

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.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 a Debug.warnOnce when window.isSecureContext indicates 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.

Comment thread src/core/secure-context-warning.js Outdated
Comment thread src/core/secure-context-warning.js Outdated
- 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.
@mvaligursky mvaligursky merged commit 1debbe7 into main May 20, 2026
8 checks passed
@mvaligursky mvaligursky deleted the feat/secure-context-warning branch May 20, 2026 10:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants