Skip to content

feat(browser-context): add a virtual clipboard#41741

Open
dcrousso wants to merge 1 commit into
microsoft:mainfrom
dcrousso:fix-15860
Open

feat(browser-context): add a virtual clipboard#41741
dcrousso wants to merge 1 commit into
microsoft:mainfrom
dcrousso:fix-15860

Conversation

@dcrousso

Copy link
Copy Markdown
Contributor

add a new browserContext.clipboard for reading and writing rich content (e.g. text/html), binary data (e.g. image/png), and plain text

it leverages a per-context store that shims and shares navigator.clipboard, native ControlOrMeta+c/ControlOrMeta+v (via trusted event interception), and document.execCommand across every page

copy, cut, and paste dispatch a real ClipboardEvent with a populated DataTransfer so that page handlers can read and override clipboardData like they would in a real browser

with one exception as Firefox does not expose clipboardData on a synthesized paste event

the shim is installed lazily on the first browserContext.clipboard use, or eagerly via browserContext.clipboard.install() (e.g. for pages that only exercise native keyboard shortcuts)

note that navigator.clipboard is only redirected where the browser already exposes it and rejects types it cannot write since that API has additional restrictions (unlike native keyboard interactions)

fixes #15860

add a new `browserContext.clipboard` for reading and writing rich content (e.g. `text/html`), binary data (e.g. `image/png`), and plain text

it leverages a per-context store that shims and shares `navigator.clipboard`, native `ControlOrMeta+c`/`ControlOrMeta+v` (via `trusted` event interception), and `document.execCommand` across every page

copy, cut, and paste dispatch a real `ClipboardEvent` with a populated `DataTransfer` so that page handlers can read and override `clipboardData` like they would in a real browser

with one exception as Firefox does not expose `clipboardData` on a synthesized `paste` event

the shim is installed lazily on the first `browserContext.clipboard` use, or eagerly via `browserContext.clipboard.install()` (e.g. for pages that only exercise native keyboard shortcuts)

note that `navigator.clipboard` is only redirected where the browser already exposes it and rejects types it cannot write since that API has additional restrictions (unlike native keyboard interactions)
@dcrousso dcrousso changed the title feat(browser-context): add a virtual clipboard for pages feat(browser-context): add a virtual clipboard Jul 10, 2026
@github-actions

Copy link
Copy Markdown
Contributor

Test results for "MCP"

1 failed
❌ [firefox] › mcp/annotate.spec.ts:230 › should capture annotations via show --annotate @mcp-macos-latest-firefox

7759 passed, 1249 skipped


Merge workflow run.

@github-actions

Copy link
Copy Markdown
Contributor

Test results for "tests 1"

3 failed
❌ [webkit-library] › library/browsercontext-virtual-clipboard.spec.ts:142 › should capture native Ctrl+C into context.clipboard @webkit-ubuntu-22.04-node20
❌ [webkit-library] › library/browsercontext-virtual-clipboard.spec.ts:224 › should install the virtual clipboard via install() @webkit-ubuntu-22.04-node20
❌ [webkit-library] › library/browsercontext-virtual-clipboard.spec.ts:233 › should let a page copy handler override the copied content @webkit-ubuntu-22.04-node20

6 flaky ⚠️ [chromium-library] › library/chromium/oopif.spec.ts:282 › should click `@chromium-ubuntu-22.04-arm-node20`
⚠️ [chromium-library] › library/video.spec.ts:275 › screencast › should capture navigation `@chromium-ubuntu-22.04-arm-node20`
⚠️ [chromium-library] › library/video.spec.ts:645 › screencast › should capture full viewport `@chromium-ubuntu-22.04-arm-node20`
⚠️ [chromium-library] › library/video.spec.ts:717 › screencast › should work with video+trace `@chromium-ubuntu-22.04-node24`
⚠️ [chromium-library] › library/video.spec.ts:680 › screencast › should capture full viewport on hidpi `@chromium-ubuntu-22.04-node20`
⚠️ [firefox-page] › page/page-emulate-media.spec.ts:144 › should keep reduced motion and color emulation after reload `@firefox-ubuntu-22.04-node20`

49730 passed, 1162 skipped


Merge workflow run.

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.

[Feature] a dedicated clipboard API

1 participant