Fix navigator.clipboard.writeText in @electron/remote MenuItem handlers#2754
Conversation
…-2R) navigator.clipboard.writeText() requires the window to be focused and a user gesture in the current browsing context. When the menu item's click handler is invoked via @electron/remote IPC, the browsing context has changed and the Web Clipboard API throws 'Unknown error'. Use @electron/remote's clipboard module instead, which routes through Electron's main-process clipboard API and works regardless of window focus or browsing context. Fixes MAILSPRING-CLIENT-2R Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GqXVeX65b7daqB5rU4jTuJ
|
The same focus/browsing-context bug fixed in MAILSPRING-CLIENT-2R existed in four other files that call navigator.clipboard.writeText() from @electron/remote MenuItem click callbacks. Use @electron/remote's clipboard module instead, which is synchronous and works regardless of window focus. Affected files: - event-attendees-input.tsx (Copy participant email) - participants-text-field.tsx (Copy participant email) - evented-iframe.tsx (Copy Email Address / Copy Link Address / Copy text) - thread-list-context-menu.ts (Copy mailbox permalink) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GqXVeX65b7daqB5rU4jTuJ
Same @electron/remote IPC focus/gesture issue fixed in the rest of the PR. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GqXVeX65b7daqB5rU4jTuJ
Sentry Issue
MAILSPRING-CLIENT-2R — 16 users affected, 30 events, ongoing since May 2026
Root Cause
When a user right-clicks on a contact name/email in the message header, a context menu appears with a "Copy email address" item. Clicking it called
navigator.clipboard.writeText(contact.email), which reportedError: Unknown errorto Sentry.The context menu's
clickhandler is invoked via@electron/remoteIPC — the main process calls back into the renderer via IPC after the menu item is selected. At that point:navigator.clipboard.writeText()is a Web Clipboard API that requires both a transient user gesture and an active, focused browsing contextFix
Replace
navigator.clipboard.writeText()with@electron/remote'sclipboard.writeText(), which routes through Electron's main-process clipboard API and works regardless of window focus. As a bonus, the call is now synchronous so there's no unhandled promise rejection.This pattern was present in five files — all fixed in this PR:
app/internal_packages/message-list/lib/message-participants.tsx— Copy contact email (original Sentry report)app/internal_packages/main-calendar/lib/core/event-attendees-input.tsx— Copy event attendee emailapp/src/components/participants-text-field.tsx— Copy participant emailapp/src/components/evented-iframe.tsx— Copy Email Address / Copy Link Address / Copy selected textapp/internal_packages/thread-list/lib/thread-list-context-menu.ts— Copy mailbox permalink🤖 Generated with Claude Code
https://claude.ai/code/session_01GqXVeX65b7daqB5rU4jTuJ