Skip to content

fix(electron): support clipboard writes from renderer - #1167

Open
freaklabx wants to merge 1 commit into
webadderallorg:mainfrom
freaklabx:fix/clipboard-copy-electron
Open

freaklabx wants to merge 1 commit into
webadderallorg:mainfrom
freaklabx:fix/clipboard-copy-electron

Conversation

@freaklabx

@freaklabx freaklabx commented Oct 26, 2026 •

Copy link
Copy Markdown

Description

Add a small Electron clipboard IPC path and route cloud share links, copied error toasts, and export error copying through a shared copyText helper. The helper uses Electron when available and retains the browser clipboard fallback.

Motivation

On macOS with Recordly v1.4.0, copying a cloud share link fails with “Could not copy link.” The permission handlers in electron/main.ts delegate to the policy in electron/permissionPolicy.ts, which only grants the trusted media permission; Chromium's clipboard write permission is denied. This change keeps that policy intact and writes through Electron's main-process clipboard API instead.

Fix

  • Validate that clipboard IPC comes from a Recordly BrowserWindow main frame whose document matches a trusted renderer URL, and accept only strings up to 100,000 characters (handler and sender check, IPC handler).
  • Expose the IPC through preload and the electronAPI type (preload).
  • Use the shared helper for cloud sharing, toast error copying, and export error copying (helper).

Type of Change

  • Bug Fix

Related Issue(s)

PR #1112 also discusses an IPC clipboard fallback. This PR keeps the fix focused on the clipboard path and avoids the broader, conflicting changes in that proposal.

Screenshots / Video

Not applicable; this fixes clipboard behavior without changing the UI.

Testing Guide

  • npm test -- --reporter=dot — 1,607 passed, 35 skipped.
  • npm run typecheck — passed.
  • npm run lint — passed with one existing useExhaustiveDependencies warning in src/components/video-editor/dashboard/ProjectThumbnail.tsx.
  • Focused copy/toast tests pass (npx vitest run src/lib/copyText.test.ts src/components/ui/toast.test.ts).

Checklist


Thank you for contributing!

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Clipboard copying now works through the app’s native clipboard integration when available, with browser clipboard support as a fallback.
  • Improvements
    • Copy actions for share links and error messages use a consistent clipboard experience, while keeping their existing success and failure notifications.

@coderabbitai

coderabbitai Bot commented Oct 26, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review.

Recent review info
Run configuration
Commits

Reviewing files that changed from the base of the PR and between 109ca3a and 33f7fa0.

Files selected for processing: 8
  • electron/electron-env.d.ts
  • electron/main.ts
  • electron/preload.ts
  • src/components/ui/toast.tsx
  • src/components/video-editor/cloud/CloudShareButton.tsx
  • src/components/video-editor/layout/EditorExportMenu.tsx
  • src/lib/copyText.test.ts
  • src/lib/copyText.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Walkthrough

The change adds an Electron clipboard IPC method and a shared copyText utility. The utility uses Electron when available and the browser clipboard API otherwise. Three UI actions now use the utility, and tests cover its selection and rejection behavior.

Changes: Clipboard writing

Layer / File(s) Summary
Electron clipboard IPC bridge
electron/electron-env.d.ts, electron/main.ts, electron/preload.ts
The preload bridge exposes clipboard writing through IPC. The main process checks the sender frame and text type and length before writing to the system clipboard.
Shared clipboard utility and tests
src/lib/copyText.ts, src/lib/copyText.test.ts
copyText uses the Electron API when available and otherwise uses the browser clipboard API. Tests cover both paths and Electron rejection propagation.
UI clipboard actions
src/components/ui/toast.tsx, src/components/video-editor/cloud/CloudShareButton.tsx, src/components/video-editor/layout/EditorExportMenu.tsx
Three UI actions use copyText instead of calling the browser clipboard API directly. Existing success and failure handling remains in place.

Priority: Normal

Estimated code review effort: 3 (Moderate) | ~20 minutes

Change: Bug fix

Sequence Diagram(s)

sequenceDiagram
  participant UI as UI action
  participant Copy as copyText
  participant Bridge as electronAPI
  participant Preload as Electron preload
  participant Main as Electron main process
  participant Clipboard as System clipboard
  participant Browser as Browser clipboard API
  UI->>Copy: submit text
  alt Electron API is available
    Copy->>Bridge: writeClipboardText(text)
    Bridge->>Preload: invoke write-clipboard-text
    Preload->>Main: IPC request
    Main->>Clipboard: write validated text
  else Electron API is unavailable
    Copy->>Browser: writeText(text)
  end
Loading

Possibly related issues

  • webadderallorg/Recordly issue 1050: The change updates copying error text in the export interface, but does not fix the reported Lightning export failure.
  • webadderallorg/Recordly issue 1067: The change updates the export error copy action, but does not address the reported auto-zoom or export failures.
  • webadderallorg/Recordly issue 1157: The change updates the export error copy path, but does not fix the reported H.264 or _resourceType errors.

Suggested reviewers: webadderall

Merge Risk: Minimal · up to 33f7f

The clipboard change is mergeable after normal checks; the supported renderer windows can use the new clipboard path.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 8 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly describes the main change: adding renderer clipboard support through Electron.
Description check Passed The description includes the purpose, motivation, implementation details, change type, related work, testing results, screenshots status, and checklist.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Finishing Touches
🧪 Generate unit tests (beta)
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant