Fix crypto.randomUUID crash over plain HTTP (non-secure context)#149
Merged
Conversation
crypto.randomUUID() is only available in secure contexts (HTTPS or localhost), so accessing the UI over plain HTTP via a LAN host throws "TypeError: crypto.randomUUID is not a function". Add a randomUUID() helper that falls back to a v4 UUID built from crypto.getRandomValues() (available in non-secure contexts), then Math.random() as a last resort. Use it in chatStore and ChatInput.
4 tasks
pufit
pushed a commit
that referenced
this pull request
Jun 27, 2026
) navigator.clipboard is only exposed in secure contexts (HTTPS or http://localhost). When the UI is accessed over plain HTTP via a LAN hostname/IP, or behind a proxy without a trusted cert, the entire clipboard object is undefined and any call throws 'TypeError: Cannot read properties of undefined (reading writeText)'. Two affected call sites: - web/src/components/Chat/CodeBlock.tsx — the per-code-block Copy button - web/src/pages/ChatPage.tsx — Cmd+Shift+C 'copy last response' shortcut Both silently failed without surfacing any UI feedback. Add a shared copyToClipboard helper that prefers navigator.clipboard when available and falls back to a hidden off-screen <textarea> + document.execCommand('copy'). execCommand is deprecated but still implemented in every browser we care about. Mirrors the same non-secure-context fallback pattern already used in utils/uuid.ts (introduced by #149).
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.
Accessing the web UI over plain HTTP via a LAN host (e.g.
http://192.168.x.x:8900or a.localname) crashes with:Cause
crypto.randomUUID()is only exposed in secure contexts — HTTPS orhttp://localhost. Over plain HTTP to any other host,crypto.randomUUIDisundefined, so the two call sites that generate client-side ids throw.Fix
New
web/src/utils/randomUUID()helper with graceful degradation:crypto.randomUUID()when available (secure context),crypto.getRandomValues()— which is available in non-secure contexts,Math.random()as a last resort (these ids are only client-side keys, never security-sensitive).Wired into the two existing usages:
stores/chatStore.ts— virtual session idcomponents/Chat/ChatInput.tsx— attachment idThese were the only
crypto.randomUUIDuses; nocrypto.subtleusage exists that would hit the same restriction.Testing
npm run buildpasses (tsc + vite).