Skip to content

fix: handle clipboard API failure in CopyButton (fixes #172) - #177

Open
slsgzs-cloud wants to merge 1 commit into
getsotto:mainfrom
slsgzs-cloud:fix-copy-button-clipboard-failure
Open

fix: handle clipboard API failure in CopyButton (fixes #172)#177
slsgzs-cloud wants to merge 1 commit into
getsotto:mainfrom
slsgzs-cloud:fix-copy-button-clipboard-failure

Conversation

@slsgzs-cloud

Copy link
Copy Markdown

Fixes #172

The CopyButton on the landing page called navigator.clipboard.writeText() without checking availability or handling rejection. When the clipboard API was unavailable (e.g., non-secure context) or the write was rejected (e.g., permissions), the user got no feedback and the handler threw or left an unhandled rejection.

Changes:

  • Added a three-state status state (idle / copied / failed) replacing the boolean copied
  • Guard against navigator.clipboard being undefined
  • try/catch the write to surface failures
  • Button text shows Copy failed for 2 seconds when the write fails, falling back to Copy on timeout (same 2s behavior as the success case)
  • No changes to the success path: Copied appears for 2s then resets

@Maxerns Maxerns left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the contribution, couple things before this can merge, per the issue:

  1. Improve the clipboard failure message

    The failure case needs a short message asking the user to select and copy the command manually.

    The command is already selectable, but showing only Copy failed on the button doesn't tell the user what to do next.

  2. Add Playwright regression coverage

    Please add regression cases to web/e2e/funnel.spec.ts covering:

    • Successful copy
    • Rejected clipboard write
    • Unavailable Clipboard API
    • Successful retry after a failure

    Please override the browser Clipboard API in the tests so the cases are deterministic.

    The existing landing-page test in that spec is a good pattern to follow.

  3. Sign off the commit and document checks

    Please sign off the commit as described in CONTRIBUTING.md:

    git commit -s

    Also update the PR body with the checks you ran from web/:

    • build:wasm
    • typecheck
    • build
    • Playwright

Happy to re review once those are in.

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.

Landing page: show a helpful message when copying the install command fails

2 participants