Skip to content

Copy to Clipboard

Install the required plugin:

Terminal window
tynd add clipboard
import { clipboard } from "@tynd/plugin-clipboard/client";
await clipboard.writeText("Hello, world");
const got = await clipboard.readText();

clipboard.writeImage takes a base64-encoded PNG string. Convert a canvas to PNG, strip the data-URL prefix, write it.

const canvas = document.querySelector("canvas")!;
const dataUrl = canvas.toDataURL("image/png");
const base64 = dataUrl.replace(/^data:image\/png;base64,/, "");
await clipboard.writeImage(base64);

Reading an image (returns { png, width, height } with png as base64):

const img = await clipboard.readImage(); // null if no image
if (img) {
const el = document.createElement("img");
el.src = `data:image/png;base64,${img.png}`;
el.width = img.width;
el.height = img.height;
document.body.appendChild(el);
}
await clipboard.writeHtml(`<p><b>Hello</b> <i>world</i></p>`);

Paste into a rich-text target (email, Google Doc) → formatted content. Plain-text targets get a stripped fallback (the OS handles this).

await clipboard.clear();

Related: clipboard API.