eneshecan / whatsapp-for-linux

An unofficial WhatsApp desktop application for Linux.
GNU General Public License v3.0
947 stars 97 forks source link

Can't paste images into chat #79

Open emyller opened 3 years ago

emyller commented 3 years ago

Description Having the chat text box focused, one can't paste images from the clipboard in it. For now, the user has to attach an image and select one from the file system.

To Reproduce Steps to reproduce the behavior:

  1. Copy some image content to the clipboard, e.g. a screenshot.
  2. Open a chat and focus on the text box.
  3. Paste the contents, nothing happens.

Expected behavior The client should accept the contents from the clipboard and display a preview for the image, allowing to add a description, etc -- a WhatsApp feature, I believe.

Screenshots image

Environment

eneshecan commented 3 years ago

Hi @emyller. Normally, if I copy the path from my file manager, it works. Could you tell me how do you copy and what you get when you paste it to another text area i.e. your browser's search bar?

vfmatzkin commented 3 years ago

Hi, I found this issue when I experienced this problem. Another example is when copying an image displayed in the web browser (like this one) via the right click->copy image, and trying to paste it in whatsapp-for-linux.

Normally, a text field shouldn't display anything when pasting this img copied contents, but if it supports images (as whatsapp web), it should load the image. Anyway, sometimes (I don't remember exactly where) when pasting the image in a text field, a base64 encoding of the image may appear.

eneshecan commented 3 years ago

@vfmatzkin Thanks a lot, makes sense. So, it doesn't work with the images copied into memory I guess, not with image paths.

emyller commented 3 years ago

@eneshecan Sorry, I forgot to reply to your first message. @vfmatzkin Thank you for adding the context!

antaxiom commented 3 years ago

Any updates on this? I need this feature frequently and end up opening it on my browser far too much.

CleoMenezesJr commented 3 years ago

Any prediction of when this feature will come?

eneshecan commented 3 years ago

Unfortunately not soon as I am not fully available until the end of June. Sorry for the inconvenience... I think it requires a bit of work involving handling some clipboard data in webkit2gtk but I didn't have a chance to look closely. If someone tries to do it, I can review and merge.

eneshecan commented 2 years ago

Here I tried to do this in a separate branch, yet without success. https://github.com/eneshecan/whatsapp-for-linux/tree/feature/paste_image_buffer. Any help is appreciated.

rodrigost23 commented 2 years ago

I just tried the following JavaScript code in both WhatsApp-for-Linux and Firefox:

document.onpaste = function (event) {
    console.log(event);

    var items = (event.clipboardData || event.originalEvent.clipboardData).items;

    for (var index in items) {
        var item = items[index];
        if (item.kind === 'file') {
            var blob = item.getAsFile();
            var reader = new FileReader();
            reader.onload = function (event) {
                console.log(event.target.result);
            }; 
            reader.readAsDataURL(blob);
        } else {
            console.log(item);
        }
    }
};

When pasting an image in Firefox, the event.clipboardData.items contains one item. In WhatsApp for Linux, this object is empty, even though the event gets fired. When pasting text, it works perfectly.

Apparently, that is the event WhatsApp Web uses to get a pasted image.

EDIT: Epiphany also doesn't support this.

rodrigost23 commented 2 years ago

Relevant issue from Tangram: sonnyp/Tangram#103. Relevant bug from WebKit's BugZilla: https://bugs.webkit.org/show_bug.cgi?id=218519

Apparently this needs to be fixed by WebKit then?

pempek commented 2 years ago

Related to this issue, I also want to add that it seems like copying image from WhatsApp for Linux doesn't seem to work.

I tried copying an image from WhatsApp for Linux and pasting it to other chat apps (Telegram, Slack), doesn't work.

I can confirm that I'm able to do this on Telegram and Slack by copy pasting images from the internet browser.

eneshecan commented 2 years ago

Relevant issue from Tangram: sonnyp/Tangram#103. Relevant bug from WebKit's BugZilla: https://bugs.webkit.org/show_bug.cgi?id=218519

Apparently this needs to be fixed by WebKit then?

Seems like it. Maybe there are some workarounds we can apply but until then, this seems to be on their side.

ravenlost commented 2 years ago

Hi guys. No actual updates / workarounds for this issue yet ? I copy/paste screenshot images all the time for work purposes and definitely do not want to have to save all images on hdd before sending over... This problem makes me have to use the web version of whatsapp, which I dislike a lot... Any progress on this would be great! Cheers for the status update and time with this :)

antaxiom commented 2 years ago

I don't really have a solution for you, but I currently run chromium with the --app flag as a way to sort of have whatsapp as a separate browser.

On Mon, Nov 15, 2021 at 6:01 AM ravenlost @.***> wrote:

Hi guys. No actual updates / workarounds for this issue yet ? I copy/paste screenshot images all the time for work purposes and definitely do not want to have to save all images on hdd before sending over... This problem makes me have to use the web version of whatsapp, which I dislike a lot... Any progress on this would be great! Cheers for the status update and time with this :)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/eneshecan/whatsapp-for-linux/issues/79#issuecomment-968724066, or unsubscribe https://github.com/notifications/unsubscribe-auth/AJRW3AS7RMXLEF7GOF4ROETUMDK6XANCNFSM4V4V7SCQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

ravenlost commented 2 years ago

Ok, thanks for the update. I'll look into doing something like that for now.

SolidCapo commented 2 years ago

Hi, any progress on this? hope it can be done soon...would appreciate it a lot! cause it's even more important than videocalls i think :) You can do it! :D

eneshecan commented 2 years ago

Just checked epiphany if it does work there since they use webkit2gtk too. Unfortunately, it's the same situation. I tried a couple of things as well but I am out of solutions right now.

CleoMenezesJr commented 2 years ago

I believe this issue should be closed. This problem is related to WebkitGTK as we can see here. In my humble opinion I suggest either creating an initiative for a workaround or making the problem visible so that more people can contribute directly to WebKit.

SolidCapo commented 2 years ago

Well, meanwhile, searching found a very good solution that can do the paste images from clipboard for whatsapp, it's called Ferdi - https://getferdi.com/ and now i'm happy cause i can have all the messengers in one place :)

Sadi58 commented 2 years ago

@SolidCapo Thanks! Recently some issues made me abandon Franz, and start using whatsapp-for-linux instead, but Ferdi looks like a good replacement for Franz indeed.

SolidCapo commented 2 years ago

@SolidCapo Thanks! Recently some issues made me abandon Franz, and start using whatsapp-for-linux instead, but Ferdi looks like a good replacement for Franz indeed.

I think it will help you too, the only thing i hope one day will be available, are the videocalls in whatsapp and messenger :+1:

emanuelserpa commented 2 years ago

Would be cool if we had something like this in AUR: https://github.com/ttys3/archlinux-webkit2gtk

mohammad-aqajani commented 2 years ago

install on Ubuntu with snap, also having problem pasting images and files!!!

serhumanos commented 1 year ago

Hi! Do you think this feature is possible?

emanuelserpa commented 1 year ago

Hi! Do you think this feature is possible?

This is a problem with WebKit that strangely wasn't solved for a long time, even though it has a patch that solves it.

https://aur.archlinux.org/packages/webkit2gtk-imgpaste

eneshecan commented 1 year ago

I don't want to depend on that aur package instead of the stable one. If someone wants to create a different package depending on the fixed aur version i.e. whatsapp-for-linux-imgpaste, please welcome.

emanuelserpa commented 1 year ago

I don't want to depend on that aur package instead of the stable one. If someone wants to create a different package depending on the fixed aur version i.e. whatsapp-for-linux-imgpaste, please welcome.

I don't think you need to do that, the AUR package already provides webkit2gtk. But I think this info would be cool to have this info in a pinned comment in the AUR package page.

eneshecan commented 1 year ago

Done!

saozer commented 1 year ago

I think there is an event listener for Paste action. Here is my suggestion according to my skill in other languages. As I told you last time, I am new with C#. But Truly, there is a Clipboard object in C#. try to understand the logic bellow

public void TextBox1_Paste(){
    if (Clipboard.ContainsImage()){
           TextBox1.addContent(Clipboard.getImage());
    }
}

There is an Object with image's Methods for clipboard

    Clipboard.ContainsImage(); // return True/false
    Clipboard.getImage(); // get image from clipboard
    Clipboard.setImage(); // put an image in the clipboard

here is a link to How to use the clipboard Class. Clic here to launch!. But if i try to understand Whatsapp, it is like a mail: you have a message and its attachements. So, may be clipboard's images are like attachements. According to this new point of view. the code should be like this:

public void TextBox1_Paste(){
    if (Clipboard.ContainsImage()){
           pastePopUp.show();
           pastePopUp.imageList.addImage(Clipboard.getImage());
           GobalMassage_var.addAttachement(Clipboard.getImage());
    }
}

It is not what you expect but in my mind it could look like that

wokawoka commented 1 year ago

I am experiencing the same issue: I can't paste any image o the chat. I'm on Pop os 21.10 + KDE 5.24.4 I am not experiencing the same problem with other whatsapp clients for linux such as https://github.com/oOthkOo/whatsapp-desktop or https://github.com/WAClient/WALC

dimisjim commented 11 months ago

Same issue. Using ubuntu 23.04 with wayland

eduxapo commented 11 months ago

same issue using manjaro arch with xorg

WaxArsatia commented 10 months ago

is this solved yet?

tom-james-watson commented 10 months ago

Please just give the issue a thumbs up if you also want this to be fixed. Adding a "+1" / "Any updates?" comment and notifying everyone in the thread is not useful. If there were updates they would be posted here.

emanuelserpa commented 10 months ago

This issue is a WebKitGTK bug and the "fix" is installing a patched webkitgtk like webkit2gtk-imgpaste

bayazidbh commented 10 months ago

On AUR, that would have to be handled by the user, yes. But is it not possible to ship that version of webkit2gtk in platforms like Flatpak, Snaps, and Nixpkgs?

edugmes commented 9 months ago

Have you guys found any solution? I have it currently installed on Ubuntu 22.04.

fwosar commented 7 months ago

On AUR, that would have to be handled by the user, yes. But is it not possible to ship that version of webkit2gtk in platforms like Flatpak, Snaps, and Nixpkgs?

It should be possible to ship the patched version in containerized formats like Flatpaks. I guess nobody wants to package it though.

ericoudesu commented 5 months ago

Still no solution in 2024 ?

luispresuelgit commented 5 months ago

Don't understand the webkit bug discussion, but that shouldn't affect when copying from desktop env instead of the web borwser copying, right?

Let me explain my scenario: I use KDE plasma with Spectacl, with it, I take a custom screenshot size, then click "copy image to clipboard" button then I try to just "CRTL + V" into Whatsapp for Linux client and nothing happens.

I have to use an external tool like Kolour Paint to save it into my files (I most of the cases I don't want to save it) and then send it as an attachment. This is not an issue in Windows version of the client.

Please, if don't leave this issue unresolved in 2024

timwassenburg commented 1 month ago

I was running in the same issue, after Googling and reading this topic I removed Whatsapp for Linux and replaced it with ZapZap, problem solved.

DaviMedrade commented 1 month ago

I was able to fix this in my system (Ubuntu 24.04) by rebuilding the webkit2gtk packages with the imgpaste patches. I'll describe how I did it, but this is not a viable solution/workaround for the project as a whole. This requires running commands in the terminal and customizing system packages, which might affect other programs that use webkit2gtk.

That's why I won't go into more detail: if this is not enough for you to figure out the details on your own, you probably shouldn't be messing with it.

Anyway, first I enabled source code repos for Ubuntu packages, then I ran apt source libwebkit2gtk-4.1-0 to download the webkit2gtk source code in the specific version and with the config files and customizations used to build the official Ubuntu packages. In my case, it downloaded webkit2gtk 2.44.2.

I entered the webkit2gtk-2.44.2 directory that apt source created and ran sudo apt build-dep ., which installs all the dependencies required to build the binary packages provided by the source package in the current directory.

In the webkit2gtk-imgpaste page in AUR, below the “Dependencies” section, there is the “Sources” section, with four files. Two of them are webkit2gtk sources, not needed because apt source already obtained and set up the correct version of the sources, and the other two are the patches (EnlargeObjectSize.patch and PasteBoardGtk.patch), which I saved into the debian/patches directory of the webkit2gtk sources. In that directory there is the series file, which is a text file containing the list of patch files to apply. I just added the names of both patch files to the end of the list and saved it.

From that point on, all I had to do was make sure that I had the basic set of packages needed to build .deb packages, and follow the regular process to build binary .deb packages, which is essentially running two commands:

Once the build was finished, I left the webkit2gtk source directory (the .deb packages are saved outside of their source directory by default) and installed all the packages (replacing the ones already installed) with sudo dpkg -i *.deb.

That fixed this problem in whatsapp-for-linux. All I have to do now is keep watch over the webkit2gtk page on the Ubuntu packages website and repeat this whole process every time the official webkit2gtk packages are updated.