Copy to Clipboard
Install the required plugin:
tynd add clipboardimport { clipboard } from "@tynd/plugin-clipboard/client";
await clipboard.writeText("Hello, world");const got = await clipboard.readText();Image (base64 PNG)
Section titled “Image (base64 PNG)”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 imageif (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);}HTML (write-only)
Section titled “HTML (write-only)”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.