v145 · Web APIs · Clipboard Differ
Clipboard differ
Subscribe to clipboardchange, snapshot each change, and diff against the previous payload — surfacing what bytes flipped, mime types added/removed, and how long between updates. The event itself only fires after the user grants permission with sticky activation.
Permission required. The first read after focus needs explicit user activation
(a click or keystroke) and clipboard-read permission. If neither is granted, the event still
fires but the read promise rejects — this page shows that failure mode honestly.
permission & subscription
Checking support…
last two snapshots
previous
(none)
current
(none)
diff
(no diff yet)
event log
Waiting for clipboardchange events…
code
// Subscribe to clipboardchange (requires sticky activation + clipboard-read).
navigator.clipboard.addEventListener('clipboardchange', async () => {
try {
const items = await navigator.clipboard.read();
const text = await getText(items);
diffAgainstPrevious(text);
} catch (err) {
// Permission denied or no activation — the event still fired,
// but we cannot read the payload.
log('Event fired, read failed: ' + err.name);
}
});
async function getText(items) {
for (const item of items) {
if (item.types.includes('text/plain')) {
const blob = await item.getType('text/plain');
return await blob.text();
}
}
return '';
}