An Interest In:
Web News this Week
- April 18, 2024
- April 17, 2024
- April 16, 2024
- April 15, 2024
- April 14, 2024
- April 13, 2024
- April 12, 2024
Pasting screenshots takes way longer than pasting image files
So here's the thing;
- Take a screenshot of your screen, fully or partial, but using an utility that dumps the image to your clipboard, so you can paste it (
PrintScreen
key on Windows 10/11 or Linux,Cmd+Shift+3
on macOS). - Open this up https://eivfjo.csb.app.
- Paste the screenshot on the page with
Ctrl+V
on Windows/Linux orCmd+V
on macOS. - Remember the time printed on screen.
- Now copy an existing image from your computer, perhaps a screenshot saved to disk.
- Go back to the page and paste it.
- See any difference?
Here's how it worked out for me (I'm using Chrome on Windows, by the way); the first paste, from the screenshot just taken, took about 500ms
--I'm on a 4k display, YMMV. The second one took 0ms
.
Now I'll reveal it to you. We're doing nothing. Okay, it's not technically nothing. But we're not really doing anything useful or that should take too long for that matter.
You can check the code over on CodeSandbox, but I'll quote the infringing line below;
void event.clipboardData.files;
If you're not familiar or need a refresher, void
simply evaluates the expression and returns undefined. That's it. We might as well omit it. I only added it to make it explicit we're doing nothing.
I haven't managed to find anything on it but my wild guess is that it isn't the browser's fault. Perhaps the underlying implementation exposes the clipboard as a filesystem but a lazy one where the image is encoded on read instead of preemptively? I don't know.
It's a problem in any case because for one I can't even show the user some feedback that something's going on since the event handlers block the main thread--the next frame doesn't start until it's finished, so any changes to DOM, like adding a loading
class to an element, also don't happen until then, but it's also freezing up the whole page for that period. Yikes! :(
Any ideas?
Original Link: https://dev.to/haggen/pasting-screenshots-takes-way-longer-than-pasting-image-files-2kb7
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To