Skip to content

refactor(web): centralize clipboard copy + non-secure-context fallback#26

Open
Mingholy wants to merge 2 commits into
simpx:mainfrom
Mingholy:fix/bf6-static-copy-fallback
Open

refactor(web): centralize clipboard copy + non-secure-context fallback#26
Mingholy wants to merge 2 commits into
simpx:mainfrom
Mingholy:fix/bf6-static-copy-fallback

Conversation

@Mingholy

@Mingholy Mingholy commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Summary

Copy was open-coded across the web app with inconsistent robustness: ~10 sites called navigator.clipboard.writeText with no fallback (silently broken over http://<ip>, a non-secure context where navigator.clipboard is undefined — e.g. the deploy box), plus two components carried their own duplicated textarea+execCommand fallback.

This centralizes all of it into a single web/src/lib/clipboard.ts, backed by the copy-to-clipboard dependency (hidden element + synchronous execCommand("copy"), so it works in non-secure contexts).

New web/src/lib/clipboard.ts

  • copyText(text): boolean — plain-text copy, the one entry point.
  • copyRich({ text, html }): Promise<boolean> — registers text/html + text/plain via ClipboardItem, falls back to copyText when unavailable.

Call sites updated (13 files, net −44 lines)

  • Removed duplicated fallbacks: OnboardingDevice, PersonalRepoPanel (deleted their local copyText).
  • Fixed bare writeText (no fallback): OnboardingInfo, ShareArtifactDialog, A2ASection, SvgRenderer, CopyButton, SettingsPage, LoopPage, and PersonalRepoPanel's crypt-key copy (which bypassed even its own fallback).
  • Copy hooks in markdown-text / MarkdownBlock now route through copyText.
  • Rich copy: TableWithToolbar now calls copyRich.

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) and Terminal (xterm clipboard addon) — not copy targets.

Test plan

  • cd web && bunx tsc -b ✅ (exit 0; copy-to-clipboard ships its own types)
  • Grep confirms no navigator.clipboard.writeText remains in web/src outside lib/clipboard.ts.
  • Manual: copy buttons work over both https/secure and http://<ip> (non-secure) contexts.

🤖 Generated with Claude Code

Mingholy and others added 2 commits June 8, 2026 21:39
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>
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.

1 participant