Clipboard (window.Electron.clipboard)
Native clipboard access for what the standard web navigator.clipboard API can't do from a sandboxed renderer: images, and clearing the clipboard outright. Source: src/main/clipboard.ts, channel prefix clipboard:*. Always on, no config needed. If you only need plain text copy/paste, prefer navigator.clipboard and skip this bridge entirely.
Methods
| Method | Returns | Notes |
|---|---|---|
readText() |
Promise<string> |
|
writeText(text: string) |
Promise<void> |
|
readImage() |
Promise<string | null> |
PNG data:image/png;base64,... URL, or null when the clipboard has no image. |
writeImage(dataUrl: string) |
Promise<void> |
Accepts a PNG/JPEG data URL, same shape readImage() returns. Malformed input silently clears the clipboard instead of throwing — check readImage() afterwards to confirm if needed. |
clear() |
Promise<void> |
|
availableFormats() |
Promise<string[]> |
MIME-type-like format identifiers currently on the clipboard. |
Example
const png = await window.Electron.clipboard.readImage();
if (png) imgElement.src = png;
await window.Electron.clipboard.writeImage(canvas.toDataURL('image/png'));
.safe
Fully mirrored — window.Electron.safe.clipboard.* resolves { ok: true, data } / { ok: false, error } instead of throwing.