Reading a pasted link from the clipboard without asking for permission
Every downloader has the same first step: the visitor copies a video link from TikTok, Instagram or Facebook, then pastes it into a box. That sounds trivial until you think about who is allowed to read the clipboard. Th
Every downloader has the same first step: the visitor copies a video link from TikTok, Instagram or Facebook, then pastes it into a box. That sounds trivial until you think about who is allowed to read the clipboard.
The obvious approach is navigator.clipboard.readText(). It looks clean in a tutorial, but in a real browser it is not free. The browser treats reading the clipboard as a permission, and the permission prompt only appears after a user gesture. On some browsers it never appears at all unless the page is served over HTTPS and the user has already granted access. Worse, if the permission is denied once, the button quietly stops working, and the visitor has no idea why.
So I never ask. On ramrom.io, the link box does not read the clipboard. It waits for the visitor to paste, and listens for the paste event itself.
linkInput.addEventListener('paste', (e) => {
const pasted = (e.clipboardData || window.clipboardData)
.getData('text');
handlePastedLink(pasted.trim());
});
The paste event is the honest version of the same idea. The browser hands the pasted text to the page because the visitor just chose to paste it there. No permission prompt, no Permissions API call, no stored state. The user is in control: nothing is read until they press paste themselves, and the text only ever goes where they put it.
There is a small detail that matters. The pasted text arrives in the event before the browser writes it into the input. That is actually useful. I can clean the link first — trim stray spaces and line breaks, expand a short vt.tiktok.com link, strip tracking parameters — and then decide what to do with it. If the link is from a platform I support, I show the resolve button as ready. If it is not, I say so straight away instead of letting the visitor press download and wait for an API call that was never going to work.
One thing I deliberately do not do is start the download on paste. The paste event fires the moment the link lands in the box, and it would be easy to call resolve.php right there. But that call spends API quota, and a pasted link is not consent to spend it — the visitor might have pasted the wrong link, or might just be checking the page. The tap on the download button is the consent. The paste event only prepares the ground.
There are a couple of quirks worth knowing if you build this yourself. On iOS Safari, the paste event still fires, but the way the keyboard and the long-press menu deliver the text can differ from desktop Chrome — test it on a real phone, not just in the desktop simulator. And do not rely on e.clipboardData alone: older browsers expose it as window.clipboardData, so the fallback in the snippet above is not decoration.
The wider lesson is one I keep coming back to on this site. The browser already gives you a user gesture that carries exactly the data you need. Reaching for a permission when a gesture will do is how simple pages end up with prompts nobody asked for. Listen for the paste, clean the text, and let the visitor decide what happens next.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.