freecoding.school100% FREE · NO SIGNUP
API ArcadeISSUE #8 of 23

clipboard api · readText · writeText

ApiaVSLegacy Larry
Apia saysThe async Clipboard API reads and writes the clipboard with writeText/readText.

navigator.clipboard.writeText(str) copies (returns a promise); readText() pastes. Both require a secure context (HTTPS) and usually a user gesture; reading often prompts for permission. There's also write/read for images and rich data. It replaced the old, finicky document.execCommand("copy").

Power-ups you unlock

Legacy Larry attacks — common mistakes

Boss battleCopy text to the clipboard on a button click and confirm success.

Example code

<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><button id="b">copy</button><span id="o"></span>
<script>document.getElementById('b').onclick=async()=>{try{await navigator.clipboard.writeText('7slf');document.getElementById('o').textContent=' copied!';}catch(e){document.getElementById('o').textContent=' blocked';}};</script></body></html>
▶ Open the interactive comic issue
‹ Geolocation · GetCurrentPosition · WatchPositionDrag And Drop Api · Dragstart · Drop ›