Skip to content

fix(web): add clipboard fallback for non-HTTPS contexts#32811

Open
GautamKumarOffical wants to merge 1 commit into
anomalyco:devfrom
GautamKumarOffical:fix/clipboard-fallback
Open

fix(web): add clipboard fallback for non-HTTPS contexts#32811
GautamKumarOffical wants to merge 1 commit into
anomalyco:devfrom
GautamKumarOffical:fix/clipboard-fallback

Conversation

@GautamKumarOffical

Copy link
Copy Markdown

Issue for this PR

Closes #32664

Type of change

  • Bug fix

What does this PR do?

The copy-to-clipboard button for code blocks doesn't work in opencode web when opened on localhost without HTTPS. navigator.clipboard requires a secure context in most browsers, so the button silently fails.

Added a fallback using document.execCommand('copy') when navigator.clipboard isn't available. The logic tries the modern API first, and falls back to creating a temporary textarea + execCommand if that's not possible.

How did you verify your code works?

  • Tested on localhost without HTTPS — copy button works now
  • Tested on HTTPS — existing behavior unchanged
  • Desktop app — no regression

Checklist

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

Adds a fallback using document.execCommand('copy') when
navigator.clipboard is not available (e.g., localhost without HTTPS).

Fixes anomalyco#32664
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.

Copy to clipboard button for code blocks in doesn't work when opened in localhost web

1 participant