System / 07

Clipboard.

Writes a sentinel value to the clipboard then reads it back. Confirms both directions work in this browser context.

Notes

Read needs page focus + a user gesture. Permission is granted via the Clipboard prompt the first time the page asks.

How it works

We call navigator.clipboard.writeText(sentinel) with a unique timestamped string, then immediately .readText() and compare. If both succeed and the value matches, the test passes.

Write almost always works. Read often fails on Firefox without permission, on Safari without a recent gesture, or on any browser when the page is unfocused. The failure mode is logged — we don't pretend it succeeded.

Frequently asked

Why does write succeed but read fail?

Browsers treat reading the clipboard as more sensitive than writing — a malicious page could read whatever you last copied (passwords, credit card numbers). Read requires both an active user gesture AND, in Firefox, an explicit permission. Write is more permissive but still needs HTTPS.

Why does this only work over HTTPS?

The Async Clipboard API is gated to secure contexts. On HTTP origins the calls reject immediately. Localhost is treated as secure for testing purposes.

What about copying images / files?

The modern API supports rich content via <code>navigator.clipboard.write()</code> with <code>ClipboardItem</code>. This page tests text only — the simpler and more widely supported subset.

What's execCommand('copy')?

The legacy way to copy programmatically — works without explicit permission because it requires a user gesture by spec. Deprecated but still widely used as a fallback. Modern code should use navigator.clipboard, falling back to execCommand only for old Safari.