CopyQ icon indicating copy to clipboard operation
CopyQ copied to clipboard

Images are stored as text when copied from web browsers

Open Searcher1231 opened this issue 2 years ago • 25 comments

Hi, dear. My problem is exactly the same as mentioned in the following Post:

https://github.com/hluk/CopyQ/issues/1100

but the code that was given at it does not work for me. I don't know if it is a bug in new version of CopyQ or an incompatibility between CopyQ and the new version of my browser!?

When I press F4, the following formats are listed for my images:

text/plain text/html

Thanks for any help Best Regards

Searcher1231 avatar Sep 11 '22 21:09 Searcher1231

Can you be more specific? Do you mean images are not shown in CopyQ?

Can you check installed plugins in Items tab in Preferences dialog? It should list "Images".

hluk avatar Sep 12 '22 13:09 hluk

Yes, exactly. Images (albeit just Images that I have copied them with Firefox or Chrome's "Copy Image" option) have not any thumbnail and I can not paste them as an image in other programs (e.g. PhotoShop, PaintShop, ...). Other images (i.e. Images that I have copied outside the browser) have not any problem and are copied by CopyQ correctly.

Yes I have "Images" under CopyQ -> Preferences -> Items.

2022-09-12_18-14-06

P.S.: after using the following code:

copyq:
var height = 200
var filePath = str(input())

setData(mimeHtml,
  '<img height="' + height + '" src="' + filePath + '" />'

)

my copied image thumbnails were backed and I can see them in CopyQ. But all of them are fake and no one of the images can be pasted in graphic programs.

Searcher1231 avatar Sep 12 '22 13:09 Searcher1231

Can you check clipboard if there are really any image formats after you copy them from web browser? (You can check current clipboard format with Ctrl+Shift+C from CopyQ.)

hluk avatar Sep 12 '22 14:09 hluk

Can you check clipboard if there are really any image formats after you copy them from web browser? (You can check current clipboard format with Ctrl+Shift+C from CopyQ.)

Well, I'm sure there is an image formats in clipboard after copying them from web browser, because I can paste the last copied image from clipboard to any graphic program without any problem, however, CopyQ can not show the last copied image too!

BTW, I used Ctrl+Shift+C from CopyQ and there is a snapshot for you:

2022-09-12_19-09-10

Searcher1231 avatar Sep 12 '22 14:09 Searcher1231

Well, I'm sure there is an image formats in clipboard after copying them from web browser, because I can paste the last copied image from clipboard to any graphic program without any problem, however, CopyQ can not show the last copied image too!

It does not look like there is any image data CopyQ can use in the clipboard. Some applications can get the remote image from the HTML formatted data (or maybe from the uri-list). But CopyQ by default does not make any network requests.

BTW, what is the web browser? I tested it in Firefox 104.0.1 on Fedora 36 and it provides some standard image data in clipboard so CopyQ saves them as images correctly.

hluk avatar Sep 13 '22 05:09 hluk

It does not look like there is any image data CopyQ can use in the clipboard. Some applications can get the remote image from the HTML formatted data (or maybe from the uri-list). But CopyQ by default does not make any network requests.

BTW, what is the web browser? I tested it in Firefox 104.0.1 on Fedora 36 and it provides some standard image data in clipboard so CopyQ saves them as images correctly.

I tested by FireFox_v91.13.0esr_64-bit, Chrome_v105.0.5195.102 (Official Build 64-bit) and Edge_v105.0.1343.33 (Official build 64-bit). My main Browser is FireFox. For example at the following link, no one of pictures can be copied by "Copy Image"

https://www.jaaar.com/kiosk#rows/all/

Searcher1231 avatar Sep 13 '22 07:09 Searcher1231

I tested it in Firefox 104.0.1 on Fedora 36 and it provides some standard image data in clipboard so CopyQ saves them as images correctly.

After your message, I thought maybe that is a problem with ESR version of Firefox, so I tested with the normal version (Firefox_v104.0.1). But the problem was not solved. Everything was exactly the same as previous.

P.S.: After copying the photo by "Copy Image", a file will be created from it in my Windows Temp folder. Is it possible to re-upload that file as a photo to CopyQ through a JS code for problem workaround?

Searcher1231 avatar Sep 13 '22 08:09 Searcher1231

I think the solution would be similar to this: https://github.com/hluk/CopyQ/issues/1591#issuecomment-983280874

hluk avatar Sep 13 '22 14:09 hluk

I think the solution would be similar to this: #1591 (comment)

The problem still remains

Searcher1231 avatar Sep 13 '22 17:09 Searcher1231

I'm using Brave browser on Linux, this is not only Windows now, imo. Here's is my reproduction step:

  • right click image and "Copy image"
  • see the content of clipboard using Ctrl+Shift+C
  • the clipboard really showing the image image
  • see the content of CopyQ of that image, no image image

latipun7 avatar Sep 29 '22 17:09 latipun7

@latipun7 That looks like a different issue. Did you enable "Images" plugin in Items configuration tab in Preferences? Otherwise CopyQ will not store images. It is enabled by default unless plugins are not installed at all (sometimes there is a separate package copyq-plugins).

hluk avatar Sep 30 '22 03:09 hluk

@hluk , yes, it is enabled. I'm able to see image copied to clipboard from flameshot for example. But not from browser "Copy Image". Did I miss some requirement or something? I just installed Linux and copyq (fresh install). image

When I click "Copy Image" in browser, my clipboard really did has image, so I can paste here in github comment for example. But if I copy from copyQ, when I paste here, it only the link/plain text. Here's my clipboard in CopyQ looks like: image

latipun7 avatar Sep 30 '22 14:09 latipun7

@latipun7 The image is probably not stored because of an automatic command. But that is a different issue, because you have a usable image format in clipboard. In the original issues there seems to be no image data in the system clipboard.

hluk avatar Sep 30 '22 15:09 hluk

oh, what should I do, @hluk ? Should I open new issue? Because I don't know what is blocking this image to be saved in CopyQ. I only has 1 custom auto command. image

latipun7 avatar Sep 30 '22 18:09 latipun7

@latipun7 Please open a new issue.

hluk avatar Oct 02 '22 05:10 hluk

@hluk The image is probably not stored because of an automatic command. But that is a different issue, because you have a usable image format in clipboard. In the original issues there seems to be no image data in the system clipboard.


This issue is not related to:

  • Any custom settings or commands (config).
  • Specific operating sytems.

But it is definitely related to Chromium based WebBrowsers! (See Palemoon Screenshot below for reference.)

I've had this issue for quite a while now: in Chromium, Brave¹, Vivaldi, Ungoogled Chromium, and some more. I added .bak to CopyQ's folders to start it freshly² and make some samples that can be seen below.

Note: Using Vivaldi's screenshot feature with »Copy to Clipboard« option works as intended (even with custom automatic commands).


System Infomation:

Desktop: GNOME 44 Windowing System: Wayland OS: Manjaro Linux (rolling release) Kernel: 6.1.31-2-MANJARO #1 SMP PREEMPT_DYNAMIC Laptop: Dell Latitude E5470


¹ Don't take this one for granted. ² To ~/.local/share/copyq and ~/.config/copyq

Copied Image from Vivaldi:

Image copied from Vivaldi (Screenshot from 2023-07-03 18-43-31)

Same Image copied from Palemoon:

Image copied from Palemoon (Screenshot from 2023-07-03 18-51-26)

Image copied from the Site in This Comment using Vivaldi:

Image copied from Vivaldi (Screenshot from 2023-07-03 18-35-14)

NA0341 avatar Jul 03 '23 17:07 NA0341

i'm experiencing the same thing. preview of screenshot images show up in copyq items just fine but the moment I "copy image" from chrome on windows. I get a small white box instead.

I used copyq-v3.9.3 for a long time without this sort of issue but I just recently noticed(using v6.3.2) that this white square box appears instead if the image. the only time i use to see that white square box on version 3.9.3 is when I did 'copy image' on a really high resolution image.

image

the tabs I have with images stored in clipboard saved with 3.9.3 still appear normally in 6.3.2

does anyone know which of the most recent version of copyq where this bug isn't present?

jadedgnome avatar Oct 21 '23 14:10 jadedgnome

Have the same issue:(

Version, OS and Environment

  • CopyQ 7.1.0
  • OS: Microsoft Windows [Version 10.0.19045.2673] 64bit
  • Browser: Firefox 119.0 64bit
  • Browser: Chrome 118.0.5993.90 (Official Build) (64-bit)
  • Browser: Edge 118.0.2088.69 (Official build) (64-bit)

CopyQ-Browsers-Images-issue-Video_2023-10-27_072615.webm

iG8R avatar Oct 27 '23 05:10 iG8R

I don't think I can do anything about this since the clipboard (and basically Qt framework that CopyQ uses) does not seem to provide the image data.

For me on Linux in Firefox 118.0.2, right clicking on an image on a web page and selecting Copy Image, works well. There is a variety of image formats in the clipboard:

❯ copyq clipboard \?
text/html
text/_moz_htmlinfo
text/_moz_htmlcontext
image/png
image/jpeg
image/bmp
image/x-bmp
image/x-MS-bmp
image/x-icon
image/x-ico
image/x-win-bitmap
image/vnd.microsoft.icon
application/ico
image/ico
image/icon
text/ico
image/tiff
image/webp
audio/x-riff

Not sure why you see application/x-qt-image or even application/x-qt-windows-mime;value="PNG" but no usable image format.

Can you check if in your CopyQ installation you have imageformats folder containing some DLL files?

BTW, I think it should at least be possible to transform the application/x-qt-windows-mime;value="PNG" when available to image/png automatically with the following command (here is how to add the command to CopyQ):

[Command]
Automatic=true
Command="
    copyq:
    setData('image/png', input())"
Icon=\xf1c5
Input="application/x-qt-windows-mime;value=\"PNG\""
Name=Store Windows PNG

hluk avatar Nov 01 '23 15:11 hluk

I don't think I can do anything about this since the clipboard (and basically Qt framework that CopyQ uses) does not seem to provide the image data.

But what happened? It used to work before, definitely in 3.x versions. Moreover, this bug only applies to copying in browsers, any of them. Copying from any other apps, the images are saved as images. And also this bug with the inability to copy any images larger than a certain size. https://github.com/hluk/CopyQ/issues/2523 It seems that it's all interconnected.

Unfortunately, the copyq clipboard \? command does not work the same way in Windows as it does in Linux. image

In the imageformats folder, I have the following files:

qsvg.dll
qwebp.dll
qwbmp.dll
qtiff.dll
qtga.dll
qicns.dll
qjpeg.dll
qico.dll
qgif.dll

BTW, I think it should at least be possible to transform the application/x-qt-windows-mime;value="PNG" when available to image/png automatically with the following command (here is how to add the command to CopyQ):

[Command]
Automatic=true
Command="
    copyq:
    setData('image/png', input())"
Icon=\xf1c5
Input="application/x-qt-windows-mime;value=\"PNG\""
Name=Store Windows PNG

Oh, thank you very much! And this already works in Edge and Chrome! But Firefox is overboard :(((((

iG8R avatar Nov 01 '23 17:11 iG8R

Found something, maybe it will somehow give you some idea on how to solve the pressing problem. https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/API/clipboard/setImageData

Topics, that led to the aforementioned link: https://github.com/Xpra-org/xpra-html5/issues/71 https://github.com/w3c/clipboard-apis/issues/44

iG8R avatar Nov 02 '23 05:11 iG8R

But what happened? It used to work before, definitely in 3.x versions.

Old versions of CopyQ rendered HTML items with images (and any other remote content). New versions (since v4.0.0) uses simpler rendering and does not make any network requests so the images show up as a dummy icon.

Unfortunately, the copyq clipboard \? command does not work the same way in Windows as it does in Linux.

The console output on Windows does not work for GUI apps unfortunately (https://github.com/hluk/CopyQ/issues/349).

You can use the Action dialog (F5 shortcut) in CopyQ instead with "Store standard output" set to "text/plain" to store the command output to new item.

hluk avatar Nov 02 '23 06:11 hluk

Below is a command that tries to extract the image URL from HTML and fetch the image.

A couple of downsides:

  • it uses a regular expression to find the image URL in HTML which may not work in some cases
  • it always stores the image with "image/png" format, this works in CopyQ even if the image format is JPEG but may fail when pasting to some apps (in some cases it would be possible to guess the format from URL itself but not always)
  • it does not work with HTTP redirects
[Command]
Automatic=true
Command="
    copyq:
    const regex = /<img [^>]*src=\"([^\"]+)\"/i

    if ( dataFormats().indexOf(mimeHtml) == -1
      || dataFormats().indexOf(mimeText) != -1
      || dataFormats().indexOf('image/png') != -1)
    {
        abort();
    }

    const html = str(data(mimeHtml))

    const m = html.match(regex)
    if (!m) {
        abort();
    }

    const url = decodeURIComponent(m[1]);
    var response = networkGet(url)
    if (response.status != 200) {
        abort();
    }
    setData('image/png', response.data)"
Icon=\xf1c5
Name=Fetch Image from HTML

hluk avatar Nov 02 '23 10:11 hluk

Windows & WebP

if OS is Windows , the image format is WebP.

CopyQ can not show this image.

xkonglong avatar Mar 29 '24 01:03 xkonglong