Fix navigator.clipboard crash over plain HTTP (non-secure context)#154
Merged
pufit merged 1 commit intoJun 27, 2026
Merged
Conversation
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 ClickHouse#149).
pufit
approved these changes
Jun 27, 2026
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.
Problem
navigator.clipboardis only exposed in secure contexts — HTTPS orhttp://localhost. When the UI is accessed over plain HTTP via a LAN hostname/IP (e.g.http://192.168.x.x:8900, a.localmDNS name, a Tailscale IP with a self-signed cert, or a proxy without a trusted cert), the entireclipboardobject isundefinedand any call throws synchronously:Two affected call sites, both silently failed without any UI feedback:
web/src/components/Chat/CodeBlock.tsx— the per-code-block Copy button.web/src/pages/ChatPage.tsx— theCmd+Shift+C"copy last response" keyboard shortcut.Same root cause as #149 (which fixed
crypto.randomUUIDover plain HTTP). Both APIs gate on secure context.Fix
Add a shared
copyToClipboardhelper inweb/src/utils/clipboard.tsthat prefersnavigator.clipboardwhen available and falls back to a hidden off-screen<textarea>+document.execCommand('copy').execCommandis deprecated but still implemented in every browser we care about.Both call sites switched to the helper.
grepconfirms no othernavigator.clipboardusages in the frontend.Style
Mirrors
utils/uuid.tsfrom #149 — same file naming convention, same fallback layering (native → legacy), same "client-side use, no crypto strength needed" reasoning.Test plan
Cmd+Shift+Cunder plain HTTP — last assistant text lands in clipboard.navigator.clipboardpath is taken — no behavior change.npm run buildclean.🤖 Generated with Claude Code