Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
February 22, 2022 02:04 pm GMT

Pasting screenshots takes way longer than pasting image files

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?


Original Link: https://dev.to/haggen/pasting-screenshots-takes-way-longer-than-pasting-image-files-2kb7

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To