Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Images are stored as text when copied from web browsers #2084

Open
Searcher1231 opened this issue Sep 11, 2022 · 44 comments
Open

Images are stored as text when copied from web browsers #2084

Searcher1231 opened this issue Sep 11, 2022 · 44 comments
Labels
help wanted Needs a volunteer to investigate/implement the issue Windows Relates to Windows OS

Comments

@Searcher1231
Copy link

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

#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

@hluk
Copy link
Owner

hluk commented Sep 12, 2022

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 hluk added incomplete Missing information about the problem and removed bug labels Sep 12, 2022
@Searcher1231
Copy link
Author

Searcher1231 commented Sep 12, 2022

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.

@hluk
Copy link
Owner

hluk commented Sep 12, 2022

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 hluk removed the incomplete Missing information about the problem label Sep 12, 2022
@hluk hluk changed the title Is this a bug in new CopyQ version? Images are stored as text when copied from web browsers Sep 12, 2022
@Searcher1231
Copy link
Author

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

@hluk
Copy link
Owner

hluk commented Sep 13, 2022

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.

@Searcher1231
Copy link
Author

Searcher1231 commented Sep 13, 2022

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
Copy link
Author

Searcher1231 commented Sep 13, 2022

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?

@hluk
Copy link
Owner

hluk commented Sep 13, 2022

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

@Searcher1231
Copy link
Author

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

The problem still remains

@hluk hluk added help wanted Needs a volunteer to investigate/implement the issue Windows Relates to Windows OS labels Sep 14, 2022
@latipun7
Copy link

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

@hluk
Copy link
Owner

hluk commented Sep 30, 2022

@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).

@latipun7
Copy link

@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

@hluk
Copy link
Owner

hluk commented Sep 30, 2022

@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.

@latipun7
Copy link

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

@hluk
Copy link
Owner

hluk commented Oct 2, 2022

@latipun7 Please open a new issue.

@NA0341
Copy link
Contributor

NA0341 commented Jul 3, 2023

@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)

@jadedgnome
Copy link

jadedgnome commented Oct 21, 2023

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?

@iG8R
Copy link

iG8R commented Oct 27, 2023

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

@hluk
Copy link
Owner

hluk commented Nov 1, 2023

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

@iG8R
Copy link

iG8R commented Nov 1, 2023

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. #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
Copy link

iG8R commented Nov 2, 2023

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:
Xpra-org/xpra-html5#71
w3c/clipboard-apis#44

@hluk
Copy link
Owner

hluk commented Nov 2, 2023

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 (#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
Copy link
Owner

hluk commented Nov 2, 2023

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

@iG8R
Copy link

iG8R commented Nov 3, 2023

CopyQ-Image-copy-in-Firefox-Video_2023-11-03_001848.webm

@xkonglong
Copy link
Contributor

Windows & WebP

if OS is Windows , the image format is WebP.

CopyQ can not show this image.

@MarGeb1
Copy link

MarGeb1 commented Dec 13, 2024

Dear hluk,

I'm using CopyQ about two weeks now and I like it very much, but now I ran into the "image-gate" and found out, that this problem exists since 2022. Do you think that there will be a solution for this, because a clipboard manager that doesn't like images, is not exactly what I was looking for?

All I can contribute is:

  • I tested with Firefox, Opera and Edge on Win 10, all with the same result, no images in CopyQ, only white icons
  • the problem does not exist on CopyQ for Linux (running Mint 22 Cinnamon here)
  • your "Fetch Image from HTML" command didn't help and last not least
  • Clipdiary 5.7 and even the 20 years old and outdated Real Clipboard can store the images.

If I can somehow assist you, just let me know.

Markus

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

@hluk
Copy link
Owner

hluk commented Dec 13, 2024

your "Fetch Image from HTML" command didn't help and last not least

@MarGeb1 What is the clipboard content and specifically value of text/html? (See the formats in File - Show Clipboard Content dialog.)

Do you think that there will be a solution for this, because a clipboard manager that doesn't like images, is not exactly what I was looking for?

CopyQ usually works well with images. If you know about a way to get an image (without doing network requests) from a system clipboard without any known image formats, please let me know.

@MarGeb1
Copy link

MarGeb1 commented Dec 13, 2024

That's the output for the Mint desktop picture on https://linuxmint.com/edition.php?id=316:

Clipboard 1

@MarGeb1 What is the clipboard content and specifically value of text/html? (See the formats in File - Show Clipboard Content dialog.)

@hluk
Copy link
Owner

hluk commented Dec 13, 2024

Not sure why it does not work for you. The regular expressing /<img [^>]*src=\"([^\"]+)\"/i should match the value of src in the HTML (and the command should fetch the image).

Is there any error in logs?

Can you try to remove the command and add it again?

Do you use the latest CopyQ version?

Interestingly, there is also application/x-qt-image format. Not sure why Qt framework does not also provide some image/* format in that case (it is usually able to convert to multiple image formats).

@MarGeb1
Copy link

MarGeb1 commented Dec 13, 2024

That's the command I used, is it correct?

`[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`

I re-added it again but with no success.

During my tests yesterday i had several

CopyQ Warning [2024-12-12 16:35:19.430] : [qt.qpa.mime] QtWarning: Retrying to obtain clipboard.
CopyQ Warning [2024-12-12 20:21:21.133] : [qt.qpa.mime] QtWarning: Retrying to obtain clipboard.

warnings, but not today.

@MarGeb1
Copy link

MarGeb1 commented Dec 13, 2024

Here the complete warnings, sorry:

CopyQ Warning [2024-12-12 16:35:19.430] <monitorClipboard-14896>: [qt.qpa.mime] QtWarning: Retrying to obtain clipboard.
CopyQ Warning [2024-12-12 20:21:21.133] <monitorClipboard-4948>: [qt.qpa.mime] QtWarning: Retrying to obtain clipboard.

I'm using v9.1.0

@hluk
Copy link
Owner

hluk commented Dec 15, 2024

Can you try the following command to troubleshoot? It would show a popup with details if it cannot fetch an image or if it succeeds.

[Command]
Automatic=true
Command="
    copyq:
    const regex = /<img [^>]*src=\"([^\"]+)\"/i;

    if ( dataFormats().indexOf(mimeHtml) == -1 ) {
        popup('No HTML');
        abort();
    }

    if ( dataFormats().indexOf(mimeText) != -1 ) {
        popup('Contains text');
        abort();
    }

    if ( dataFormats().indexOf('image/png') != -1 ) {
        popup('Contains image');
        abort();
    }

    const html = str(data(mimeHtml));

    const m = html.match(regex);
    if (!m) {
        popup('No image available', html);
        abort();
    }

    const url = decodeURIComponent(m[1]);
    var response = networkGet(url);
    if (response.status != 200) {
        popup('Failed to fetch the image', `${url}\\nstatus code: ${response.status}`);
        abort();
    }

    popup('Adding an image', url);
    setData('image/png', response.data);"
Icon=
Name=Fetch Image from HTML

@MarGeb1
Copy link

MarGeb1 commented Dec 15, 2024

Thank you hluk.

I copied some pictures from different sites, the result was always the same:

Clipboard 1

@hluk
Copy link
Owner

hluk commented Dec 16, 2024

Hmm, that is strange. According to the previous clipboard content screenshot, there should be no text/plain format.

Can you try to update the command to the following? Specifically, it replaces dataFormats().indexOf(mimeText) != -1 check with str(data(mimeText)).trim() != ''.

[Command]
Automatic=true
Command="
    copyq:
    const regex = /<img [^>]*src=\"([^\"]+)\"/i;

    if ( dataFormats().indexOf(mimeHtml) == -1 ) {
        popup('No HTML');
        abort();
    }

    if ( str(data(mimeText)).trim() != '' ) {
        popup('Contains text');
        abort();
    }

    if ( dataFormats().indexOf('image/png') != -1 ) {
        popup('Contains image');
        abort();
    }

    const html = str(data(mimeHtml));

    const m = html.match(regex);
    if (!m) {
        popup('No image available', html);
        abort();
    }

    const url = decodeURIComponent(m[1]);
    var response = networkGet(url);
    if (response.status != 200) {
        popup('Failed to fetch the image', `${url}\\nstatus code: ${response.status}`);
        abort();
    }

    popup('Adding an image', url);
    setData('image/png', response.data);"
Icon=
Name=Fetch Image from HTML

@MarGeb1
Copy link

MarGeb1 commented Dec 16, 2024

Im really sorry but there's no difference:

Clipboard 2

@hluk
Copy link
Owner

hluk commented Dec 17, 2024

Can you please check what text (text/plain format) do the items contain? Select an item and press F4 to see the formats.

@MarGeb1
Copy link

MarGeb1 commented Dec 17, 2024

text/plain is file:///C:/Users/Markus/AppData/Local/Temp/4402013300970224452.jpg
and similar entries for the other images.

@hluk
Copy link
Owner

hluk commented Dec 18, 2024

text/plain is file:///C:/Users/Markus/AppData/Local/Temp/4402013300970224452.jpg

Interesting, so I guess you could also use that file as image.

Anyway, here is the fixed version which fetches the remote image:

[Command]
Automatic=true
Command="
    copyq:
    const regex = /<img [^>]*src=\"([^\"]+)\"/i;

    if ( dataFormats().indexOf(mimeHtml) == -1 ) {
        abort();
    }

    const text = str(data(mimeText)).trim();
    if ( text != '' && !text.startsWith('file://') ) {
        abort();
    }

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

    const html = str(data(mimeHtml));

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

    const url = decodeURIComponent(m[1]);
    serverLog('Fetching image: ' + url);
    const response = networkGet(url);
    if (response.status != 200) {
        popup('Failed to fetch the image', `${url}\\nstatus code: ${response.status}`);
        abort();
    }

    setData('image/png', response.data);"
Icon=
Name=Fetch Image from HTML

@MarGeb1
Copy link

MarGeb1 commented Dec 18, 2024

I'm sorry again...
If you feel bothered, I can go on with Clipdiary until I move to Linux next year. Then I will use CopyQ again because this issue does not exist there.
Clipboard 1

@hluk
Copy link
Owner

hluk commented Dec 19, 2024

Oops, sorry, the second if condition in the last command was wrong, 🤦‍♂️ it should be: text != '' && !text.startsWith('file://')

I've updated the command in my previous comment.

@MarGeb1
Copy link

MarGeb1 commented Dec 19, 2024

Aaaaah, looks much better now! Worked with three of my four test sites. Facebook did not, but that's not important.
Thanks for your support and have Happy Hollidays!!

Clipboard 1

@hluk
Copy link
Owner

hluk commented Dec 19, 2024

Oh, for Facebook, I think the command would need to go through some HTTP redirects or even log into an account.

It would be much better to use the image path if it is in the text/plain format. And I just remembered, there is even a command for this: Preview Image Files

@MarGeb1
Copy link

MarGeb1 commented Dec 20, 2024

That does not work 🤪. But as said, I really don't need Facebook.

Clipboard 1

@esauvisky
Copy link

Found a solution that doesn't require fetching:

global.hasImageFormat = function (formats) {
    for (const format of formats.values()) {
        if (format.startsWith('image/'))
            return true;
    }
    return false;
};

const imageMime = 'image/png';
const mimeText = 'text/plain';
const onClipboardChanged_ = onClipboardChanged;
onClipboardChanged = function () {
    if (isClipboard()) {
        const formats = dataFormats();
    
        // Fix for Chrome image issue
        const imageData = clipboard(imageMime);
        if (imageData.length > 0 || hasImageFormat(formats)) {
            removeData(mimeText)
            setData(imageMime, imageData);
        }
    }
    onClipboardChanged_();
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Needs a volunteer to investigate/implement the issue Windows Relates to Windows OS
Projects
None yet
Development

No branches or pull requests

9 participants