feat(browser): add Copy to context menu when text is selected
Fixes #7036
Summary
Adds a Copy button to the built-in browser's context menu when text is selected. Previously the context menu only showed Back/Forward/Reload and DevTools — users had to open DevTools or use keyboard shortcuts to copy text from a page.
Changes
- src/main/browser/browser-guest-ui.ts — Forwards
selectionTextandcanCopyfrom Electron's ContextMenuParams to the renderer - src/shared/browser-guest-events.ts — Adds
canCopytoBrowserGuestContextMenuEvent - src/preload/index.ts — Exposes
window.api.ui.writeClipboardText() - src/renderer/src/components/browser-pane/BrowserPane.tsx — Renders a Copy button when
canCopyis true (both local and remote webviews)
Testing
- Open the built-in browser, navigate to any page, select text, right-click → Copy button shown
- Click Copy → paste elsewhere → text is copied
- Remote webview (SSH host) → same behavior
- Right-click without selection → no Copy button
Screenshots
No visual change — standard context menu item.
[!WARNING]
Review limit reached
@nwparker, you've reached your PR review limit, so we couldn't start this review.Next review available in: 7 minutes
Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. You're only billed for reviews past your plan's rate limits ($0.25/file).
How can I continue?
After more reviews become available, a review can be triggered using the
@coderabbitai reviewcommand as a PR comment. Alternatively, push new commits to this PR.To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.
How do review limits work?
CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.
For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.
Please refer docs for additional details.
Review details
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID:
f0101651-8d49-4b55-8de0-94af6745effa📥 Commits
Reviewing files that changed from the base of the PR and between e2cf68ca1689272ed37efb5961a4b44a1186926e and 040396da1868effef508f97d46a35d2542861655.
📒 Files selected for processing (10)
src/main/browser/browser-guest-ui.test.tssrc/main/browser/browser-guest-ui.tssrc/preload/index.tssrc/renderer/src/components/browser-pane/BrowserPane.tsxsrc/renderer/src/i18n/locales/en.jsonsrc/renderer/src/i18n/locales/es.jsonsrc/renderer/src/i18n/locales/ja.jsonsrc/renderer/src/i18n/locales/ko.jsonsrc/renderer/src/i18n/locales/zh.jsonsrc/shared/browser-guest-events.ts
📝 Walkthrough
Walkthrough
This change adds clipboard "Copy" support for text selections in the browser context menu. The shared event type, main process context-menu handler, preload IPC bridge, and renderer context-menu components are all extended with selectionText and canCopy fields. When a selection exists, both the remote and local browser pane context menus render a conditional "Copy" item that writes the selected text to the clipboard. Corresponding test expectations were updated to reflect the new payload fields.
Changes
| Area | Change |
|---|---|
| Shared types | BrowserContextMenuRequestedEvent gains selectionText and canCopy fields |
| Main process | setupGuestContextMenu populates new fields with safe defaults; test updated |
| Preload | onContextMenuRequested callback/listener typing extended |
| Renderer | Context-menu state extended; "Copy" menu item added to remote and local menus |
Sequence Diagram(s)
sequenceDiagram
participant WebContents
participant browserGuestUi as browser-guest-ui.ts
participant Preload as preload/index.ts
participant BrowserPane as BrowserPane.tsx
WebContents->>browserGuestUi: context-menu event (selectionText, editFlags)
browserGuestUi->>Preload: browser:context-menu-requested (selectionText, canCopy)
Preload->>BrowserPane: onContextMenuRequested callback (selectionText, canCopy)
BrowserPane->>BrowserPane: render Copy menu item if selectionText present
BrowserPane->>BrowserPane: write selectionText to clipboard on click
Estimated code review effort: 2/5 (~15 minutes)
Related PRs: None identified.
Related issues: None identified.
Suggested labels: browser, renderer, enhancement
Suggested reviewers: None identified.
🌸 A right-click, a highlighted word, Now a "Copy" waits, patiently heard. From guest to preload to pane it flows, selectionText travels where the clipboard goes. A small clip, a rabbit's tidy chore. 🐇
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Description check | ⚠️ Warning | The description covers summary, changes, testing, and screenshots, but it omits the required AI Review Report, Security Audit, and Notes sections. | Add the missing template sections with the AI review summary, security audit findings, and any platform-specific notes. |
✅ Passed checks (4 passed)
| Check name | Status | Explanation |
|---|---|---|
| Linked Issues check | ✅ Passed | The PR implements the requested ability to copy selected text from the built-in browser context menu, matching #7036. |
| Out of Scope Changes check | ✅ Passed | The changes stay focused on context-menu copy support and related plumbing, with no clear unrelated scope added. |
| Docstring Coverage | ✅ Passed | No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. |
| Title check | ✅ Passed | The title matches the main user-visible change: adding a Copy option to the browser context menu when text is selected. |
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.
Comment @coderabbitai help to get the list of available commands.
Took ownership of this PR (rebased onto latest main, fixed correctness bugs, verified end-to-end). Thanks @sudoeren for the original patch — the approach (read the native selection and write it straight to the clipboard) is the right one.
Description
Issue #7036 is "I can't copy to clipboard in the built-in browser; prevention should at least be opt-in." The real failure mode is page-level copy suppression: sites that call preventDefault() on the copy event block native Cmd/Ctrl+C, and Orca's custom browser context menu had no Copy affordance. Reading selectionText from the native context-menu params and writing it directly to the clipboard bypasses the page's copy handler entirely (we never dispatch a page-visible copy event), so it fixes exactly the reported case.
The original patch was on the right track but did not compile and did not work on the remote/SSH browser. My commit fixes that:
- Remote/SSH + paired-web browser now actually works.
RemoteBrowserContextMenuhad been given a requiredselectionText, but the remote setter never provided it — a realtscerror (error TS2345 … missing selectionText), and the remote Copy item could never appear. The remote context-menu eval now readswindow.getSelection()in the guest and threads it throughreadRemoteContextMenuResultand bothsetContextMenusites, so the SSH/paired-web image-streamed browser gets the same Copy affordance as the local webview (per AGENTS.md's SSH requirement). - Dropped the dead
canCopyfield. It was forwarded through the IPC event, preload, and renderer but never read — the menu already gates purely on the selection. Removing it shrinks the webview↔host IPC payload. - Gate on
selectionText.trim()so a whitespace-only selection doesn't show a pointless Copy, and added a trailing separator so Copy groups like the existing "Copy Link Address" section. The clipboard write uses the raw (untrimmed) selection, matching native copy. - Localization: the new
translate()"Copy" key was never synced into the catalog (would failverify:localization-catalogin CI). Added it to all five locales; es/ja/ko/zh mirror the existing Copy translation (Copiar/コピー/복사/复制). - Added a unit test asserting the native selection is forwarded to the renderer.
Evidence
Reproduced and verified in a real Electron dev build (/electron) against a test page that blocks copy via document.addEventListener('copy', e => e.preventDefault(), true):
- Baseline problem reproduced — native copy is blocked: after
document.execCommand('copy')and a realCmd+Ckeystroke, the OS clipboard stayed at the sentinel (pbpasteunchanged). - Fix works — select text → right-click → the menu shows
["Copy", "Back", "Forward", "Reload", "Open Page In Default Browser", "Copy Page URL", "Inspect Page"]; clicking Copy set the clipboard to the exact selection:- before:
SENTINEL_BEFORE_1783112022 - after Copy:
ORCA_COPY_SENTINEL_2036 the quick brown fox jumps over the lazy dog
- before:
- Gate correct — right-click with no selection shows
["Back", "Forward", "Reload", …]and no Copy item.
Checks:
pnpm test src/main/browser/browser-guest-ui.test.ts→ 25 passed (incl. newforwards the native selection text so the renderer can offer Copy).pnpm lint→ clean (oxlint + switch-exhaustiveness + styled-scrollbars + localization-catalog + localization-coverage). IsolatedtsconBrowserPane.tsxno longer reports theselectionText/SetStateActionerrors.- Two independent review passes (correctness + security) came back clean.
ELI5
Some websites turn off "copy" so you can't grab their text. Before, Orca's mini-browser had no Copy button in the right-click menu, so those sites left you stuck. Now, when you've highlighted text, right-click shows a Copy button that puts the highlighted text on your clipboard directly — it doesn't ask the webpage's permission, so it works even on pages that try to block copying. It also works over SSH/remote browsers now, and only shows up when you've actually selected something.
Trade-offs / regressions
- No regressions. The menu only gains a Copy item when there's a real selection; every existing item is unchanged. The
canCopyremoval is safe (grepped: no remaining references; the onlycanCopy*hits are an unrelated editor feature). - Clipboard-IPC security analysis (webview↔host boundary): clean.
window.api.ui.writeClipboardTextis pre-existing, not new — this PR adds no clipboard IPC channel. The write goes throughclipboard:writeText, which is (a) trusted-sender-gated (rejectswebviewsenders viaassertTrustedClipboardSender), (b) size-capped at 16 MB (CLIPBOARD_TEXT_WRITE_MAX_BYTES, no OOM), and (c) write-only (no clipboard read / exfiltration). The untrusted guest page can't reachwindow.api(contextIsolation, no guest preload) and can't forge the main→renderercontext-menuevent; the write requires two real user gestures (right-click, then click Copy on Orca chrome). The remote eval expression interpolates onlyJSON.stringify'd numeric coordinates, so it's injection-safe, and its result is parsed defensively.selectionTextis intentionally not redacted (it's the user's own on-screen text, mirroring native copy; it never leaves the local clipboard).