Skip to content

feat: add Clipboard API for browser clipboard access#23615

Draft
Artur- wants to merge 1 commit intomainfrom
feature/clipboard
Draft

feat: add Clipboard API for browser clipboard access#23615
Artur- wants to merge 1 commit intomainfrom
feature/clipboard

Conversation

@Artur-
Copy link
Member

@Artur- Artur- commented Feb 21, 2026

Provide a server-side Java API for the browser Clipboard API via the Clipboard interface in com.vaadin.flow.component.page.

Two categories of operations are supported:

  • Client-side copy (reliable): copyOnClick methods set up a click handler that writes to the clipboard directly in the browser event handler, satisfying the user gesture requirement in all browsers. Variants support static text, reading from a source component, copying images, and success/error callbacks.

  • Server-initiated operations: writeText, readText, and writeImage go through a server round-trip. These may not work in Firefox or Safari due to user gesture timeout constraints.

Paste events are supported via addPasteListener, which handles text, HTML, and file data (files are uploaded to the server automatically). Copy and cut event listeners are also provided.

@github-actions
Copy link

github-actions bot commented Feb 21, 2026

Test Results

 1 364 files  + 3   1 364 suites  +3   1h 20m 46s ⏱️ - 1m 24s
 9 704 tests +35   9 637 ✅ +35  67 💤 ±0  0 ❌ ±0 
10 162 runs  +36  10 086 ✅ +36  76 💤 ±0  0 ❌ ±0 

Results for commit f00593a. ± Comparison against base commit d16f71e.

♻️ This comment has been updated with latest results.

Provide a server-side Java API for the browser Clipboard API via the
Clipboard interface in com.vaadin.flow.component.page.

Two categories of operations are supported:

- Client-side copy (reliable): copyOnClick methods set up a click
  handler that writes to the clipboard directly in the browser event
  handler, satisfying the user gesture requirement in all browsers.
  Variants support static text, reading from a source component,
  copying images, and success/error callbacks.

- Server-initiated operations: writeText, readText, and writeImage
  go through a server round-trip. These may not work in Firefox or
  Safari due to user gesture timeout constraints.

Paste events are supported via addPasteListener, which handles text,
HTML, and file data (files are uploaded to the server automatically).
Copy and cut event listeners are also provided.

All JavaScript logic lives in clipboard.js, loaded via @jsmodule on
UI.java, exposing functions on window.Vaadin.Flow.clipboard.
@sonarqubecloud
Copy link

@mcollovati
Copy link
Collaborator

mcollovati commented Mar 5, 2026

I did a test with the view at https://gist.github.com/mcollovati/0090b03502eacc0bf96a4336612a2424

Seems to work fine, except for copy and cut listeners; in the example view, copied/cut text is never sent to the server. Could it be because it should be read from document.getSelection() on the client side?

EDIT: update the gist with a workaround for copy/cut listeners

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants