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.c…


This content originally appeared on DEV Community and was authored by Arthur Corenzan

So here's the thing;

  1. 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).
  2. Open this up https://eivfjo.csb.app.
  3. Paste the screenshot on the page with Ctrl+V on Windows/Linux or Cmd+V on macOS.
  4. Remember the time printed on screen.
  5. Now copy an existing image from your computer, perhaps a screenshot saved to disk.
  6. Go back to the page and paste it.
  7. 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?


This content originally appeared on DEV Community and was authored by Arthur Corenzan


Print Share Comment Cite Upload Translate Updates
APA

Arthur Corenzan | Sciencx (2022-02-22T14:04:22+00:00) Pasting screenshots takes way longer than pasting image files. Retrieved from https://www.scien.cx/2022/02/22/pasting-screenshots-takes-way-longer-than-pasting-image-files/

MLA
" » Pasting screenshots takes way longer than pasting image files." Arthur Corenzan | Sciencx - Tuesday February 22, 2022, https://www.scien.cx/2022/02/22/pasting-screenshots-takes-way-longer-than-pasting-image-files/
HARVARD
Arthur Corenzan | Sciencx Tuesday February 22, 2022 » Pasting screenshots takes way longer than pasting image files., viewed ,<https://www.scien.cx/2022/02/22/pasting-screenshots-takes-way-longer-than-pasting-image-files/>
VANCOUVER
Arthur Corenzan | Sciencx - » Pasting screenshots takes way longer than pasting image files. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/02/22/pasting-screenshots-takes-way-longer-than-pasting-image-files/
CHICAGO
" » Pasting screenshots takes way longer than pasting image files." Arthur Corenzan | Sciencx - Accessed . https://www.scien.cx/2022/02/22/pasting-screenshots-takes-way-longer-than-pasting-image-files/
IEEE
" » Pasting screenshots takes way longer than pasting image files." Arthur Corenzan | Sciencx [Online]. Available: https://www.scien.cx/2022/02/22/pasting-screenshots-takes-way-longer-than-pasting-image-files/. [Accessed: ]
rf:citation
» Pasting screenshots takes way longer than pasting image files | Arthur Corenzan | Sciencx | https://www.scien.cx/2022/02/22/pasting-screenshots-takes-way-longer-than-pasting-image-files/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.