refactor(web): centralize clipboard copy + non-secure-context fallback#26
Open
Mingholy wants to merge 2 commits into
Open
refactor(web): centralize clipboard copy + non-secure-context fallback#26Mingholy wants to merge 2 commits into
Mingholy wants to merge 2 commits into
Conversation
Introduce web/src/lib/clipboard.ts (copyText + copyRich) backed by the copy-to-clipboard dependency, which works in non-secure contexts (http://<ip>) where navigator.clipboard is undefined. Replace ~10 bare navigator.clipboard.writeText sites that had no fallback, and remove two duplicated textarea+execCommand fallbacks (OnboardingDevice, PersonalRepoPanel). TableWithToolbar's rich (text/html) copy moves into copyRich, with plain-text fallback going through the shared util. Static public/*.html landing pages keep their own inline fallback (can't import npm modules); left as-is. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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
Copy was open-coded across the web app with inconsistent robustness: ~10 sites called
navigator.clipboard.writeTextwith no fallback (silently broken overhttp://<ip>, a non-secure context wherenavigator.clipboardisundefined— e.g. the deploy box), plus two components carried their own duplicatedtextarea+execCommandfallback.This centralizes all of it into a single
web/src/lib/clipboard.ts, backed by thecopy-to-clipboarddependency (hidden element + synchronousexecCommand("copy"), so it works in non-secure contexts).New
web/src/lib/clipboard.tscopyText(text): boolean— plain-text copy, the one entry point.copyRich({ text, html }): Promise<boolean>— registerstext/html+text/plainviaClipboardItem, falls back tocopyTextwhen unavailable.Call sites updated (13 files, net −44 lines)
OnboardingDevice,PersonalRepoPanel(deleted their localcopyText).writeText(no fallback):OnboardingInfo,ShareArtifactDialog,A2ASection,SvgRenderer,CopyButton,SettingsPage,LoopPage, andPersonalRepoPanel's crypt-key copy (which bypassed even its own fallback).markdown-text/MarkdownBlocknow route throughcopyText.TableWithToolbarnow callscopyRich.Out of scope (unchanged)
public/index.html/public/index.zh.html— standalone landing pages that can't import npm modules; they keep the inline fallback added earlier in this branch (commit f8ba42f).Composer(paste handler) andTerminal(xterm clipboard addon) — not copy targets.Test plan
cd web && bunx tsc -b✅ (exit 0;copy-to-clipboardships its own types)navigator.clipboard.writeTextremains inweb/srcoutsidelib/clipboard.ts.https/secure andhttp://<ip>(non-secure) contexts.🤖 Generated with Claude Code