Class WebClipboard

java.lang.Object
java.awt.datatransfer.Clipboard
vaadinx.awt.datatransfer.WebClipboard

public final class WebClipboard extends Clipboard
The system clipboard for a Vaadin UI. Round-trips through the browser's Async Clipboard API via a small static-resource helper JS (META-INF/resources/emul/clipboard-helper.js, injected per-UI via Page.addJavaScript("context://emul/clipboard-helper.js") from Toolkit.getSystemClipboard() — see D_clipboard_helper_js. The context:// URL routes through Vaadin's static-resource handler, not Vite's bundler).

Both setContents(Transferable, ClipboardOwner) and getContents(Object) are synchronous from the caller's point of view: they park the calling virtual thread on the PendingJavaScriptResult's CompletableFuture until the browser settles. EHelper.callSwing(Runnable) provides the VT carrier that allows parking; calls from a non-VT thread or with no current UI throw IllegalStateException (R_callswing_envelope). See emulators/decisions.md §D_clipboard.

Throw / WARN split (D_clipboard_throw_warn_split).

  • Deployment-fixable failures throw. Missing secure context (plain HTTP / non-localhost), missing navigator.clipboard (ancient browser) — IllegalStateException. The migrator's affordance is to deploy over HTTPS or upgrade the browser; silent no-op would hide a deployment bug.
  • Per-call runtime failures WARN and degrade gracefully. NotAllowedError, document-not-focused, decode failures, unexpected browser errors — log via EHelper.onUnimplemented(String, String, Object...) and return an empty WebClipboardSnapshot (read) or fire-and-forget (write). Matches Swing's "clipboard had no data" semantics for read.

Test seam (D_clipboard_test_mode). setTestMode(boolean) bypasses executeJs entirely and holds the most-recently-set Transferable in a server-side field. Karibu unit tests opt in; production stays on the real path. Real-browser e2e validation of the executeJs round-trip is a separate harness (deferred slice).

One instance per Vaadin UI; obtain via Toolkit.getSystemClipboard().