Repository navigation
Fix copy buttons on the first click in Safari - #572
Merged
Merged
Conversation
added 8 commits
December 3, 2026 11:27
Safari refuses navigator.clipboard.writeText when the page has no focus or the click's activation has lapsed, so copy buttons (the disconnect keyword, API keys, MCP, Telegram, templates, links) failed with "Failed to copy to clipboard" until the user clicked the page first. copyToClipboard now goes through VueUse's useClipboard with legacy: true, which falls back to the copy command when the Clipboard API is refused. It never reports a failure, so the copy_failed toast, its lang key and the callers' didCopy checks go away. Browser tests read copies through a shared spyOnClipboard() / copiedText(), covering both paths, and a new test covers a refused Clipboard API.
Tested in real Safari: inside the confirmation dialog it refuses both navigator.clipboard.writeText (NotAllowedError) and the copy command (execCommand returns false), and VueUse's legacy fallback reports success while copying the empty selection of the focused input. A ClipboardItem written with navigator.clipboard.write() is accepted, as the share chart's image copy already did. copyToClipboard goes back to its own try/catch with write() instead of writeText(), so the copy_failed toast and the callers' checks come back, and VueUse is no longer used for it.
The real cause, traced in Safari with navigator.userActivation at each phase of the click: the user activation is still there at mousedown, and is gone once the focus moves from the dialog's text field to the copy button. Safari then refuses any clipboard write (writeText, ClipboardItem or the copy command). Later clicks worked because the button already had focus. Every copy button now prevents its mousedown, so the click never moves the focus and the activation reaches the click handler. copyToClipboard goes back to writeText, unchanged from main. The clipboard test helpers are renamed recordClipboardWrites() and lastCopiedText(), and a test checks that copying the disconnect keyword leaves the focus in the confirmation field.
Every copy button repeated the same copied ref, two-second timer and
unmount cleanup, and each one had to remember @mousedown.prevent so
Safari would allow the copy. CopyButton owns all of it: it prevents its
mousedown, copies through copyToClipboard, exposes { copied } to its slot,
can show a #copied slot in its place, resets when its value changes, and
takes as / as-child to keep each place's own button.
The confirmation keyword, disconnect keyword, MCP fields, generated API
key, Telegram command, template body, webhook secret and JSON viewer use
it. The share chart's image copy keeps its own button.
Button takes the text to copy and keeps the focus where it is, so no copy button can forget the Safari fix. ConfirmDeleteModal holds the keyword line (ConfirmKeywordField), which the disconnect dialog reuses. CopyButton is gone.
The copy state lives in Button itself, the dialogs keep their keyword line and only swap their copy button, and the tests keep their clipboard stubs.
Button resets the copied state through VueUse's refAutoReset, renders one element again and makes a copy button type=button, so it never submits a form. The API key and Telegram buttons show their copied state inside the button. Tests cover the focus, the form, the reset, a refused copy, the success toast and each copy button's text.
paulocastellano
deleted the
paulocastellano/fix-copy-clipboard-failure
branch
December 3, 2026 16:24
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.
Fixes ENG-23: "Failed to copy to clipboard" on the first click of a copy button in Safari (the disconnect keyword, API key, webhook secret, MCP URL…).
Cause
Safari drops the click's user activation when the click moves the focus out of a text field (the dialog's autofocused input). Every clipboard write is then refused (
writeText,ClipboardItem,execCommand). A second click worked because the button already had the focus. Traced in real Safari withnavigator.userActivation:pointerdown:A mousedown:A focusout(INPUT) focusin(BUTTON) pointerup:- click:-→NotAllowedErrorpointerdown:A mousedown:A pointerup:A click:A→ copiedFix
Buttontakes acopyprop (andcopy-success-message). With it, the button copies on click, never takes the focus (preventDefaulton mousedown), istype="button"so it never submits a form, and passes{ copied }to its slot for two seconds (VueUserefAutoReset). Every copy button goes through it, so none can forget the Safari fix, and each drops its own copy state.copyToClipboardis unchanged: a refused copy still toastscopy_failed.Tests
Each guard in
Buttonhas a test that fails without it (checked by removing it):copy_failedand shows nothing as copied;copy-success-messagetoasts (webhook signing secret).Each copy button copies its own text: disconnect and API key keywords, generated API key, Telegram command, webhook secret and payload, template body, MCP URL. All copy-related browser tests pass in Chromium and WebKit (
--browser safari).Manual test
For each item: click the copy button once (the first click is the one that failed in Safari), paste somewhere, and check that the pasted text is right, the copied mark shows and then goes away, and no "Failed to copy to clipboard" toast appears.
disconnect. Type the keyword and copy again: the dialog stays open and the channel stays connected.REGENERATE.disconnect.