demo · v144

State Mirror

The real motivation for clipboardchange: enabling the "paste" toolbar button without polling. Listen for the event, inspect navigator.clipboard.read() to see what types are available, and enable / disable the action accordingly — like a native app.

clipboardchange event: checking…

formats now on the clipboard

  • (subscribe to start)

last pasted preview

the API

navigator.clipboard.addEventListener("clipboardchange", async () => {
  const items = await navigator.clipboard.read();
  const types = new Set(items.flatMap(i => i.types));
  pasteBtn.disabled = !types.has("text/plain") && !types.has("image/png");
});

see also