Skip to content

fix(app): clipboard fallback so copy buttons work in non-secure contexts#17549

Open
Hastyshell wants to merge 8 commits intoanomalyco:devfrom
Hastyshell:fix/web-copy-buttons
Open

fix(app): clipboard fallback so copy buttons work in non-secure contexts#17549
Hastyshell wants to merge 8 commits intoanomalyco:devfrom
Hastyshell:fix/web-copy-buttons

Conversation

@Hastyshell
Copy link
Copy Markdown

@Hastyshell Hastyshell commented Mar 15, 2026

Issue for this PR

Closes #14803 #17553

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

navigator.clipboard.writeText() requires a secure context (HTTPS or localhost). When users run opencode web and access it over LAN via plain HTTP, every copy button in the UI silently fails — the API throws but nothing catches it, so buttons never show the "copied" state.

The fix adds a shared copy(text) utility in both the ui and web packages that tries the Clipboard API first and falls back to document.execCommand("copy") via a hidden textarea. All copy call sites are updated to use this utility.

How did you verify your code works?

Tested by accessing opencode web over HTTP on a LAN IP and clicking the Copy path button, copy code block, copy response, and copy error buttons — all now work correctly.

Screenshots / recordings

N/A (functional fix, no visual change)

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@github-actions github-actions bot added needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Mar 15, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@Hastyshell Hastyshell marked this pull request as draft March 15, 2026 04:30
All copy handlers were calling navigator.clipboard.writeText() directly,
which fails silently when the page is not in a secure context (e.g.
accessed via HTTP over LAN). Introduce a shared copy() utility that
first tries the Clipboard API and falls back to document.execCommand
so buttons work in all environments.
File.write and its test belong to a separate PR; remove them from this branch.
@Hastyshell Hastyshell force-pushed the fix/web-copy-buttons branch from d273002 to 5f82ef7 Compare March 15, 2026 04:36
@github-actions github-actions bot removed needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Mar 15, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

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.

[FEATURE]: Copy Button doesn't work in HTTP - Use document.execCommand("copy") as fallback

1 participant