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

Unable to paste images from clipboard with keyboard shortcut #148

Closed
1 of 5 tasks
TheTrio opened this issue Jun 19, 2022 · 11 comments
Closed
1 of 5 tasks

Unable to paste images from clipboard with keyboard shortcut #148

TheTrio opened this issue Jun 19, 2022 · 11 comments
Labels
info:discord-web An upstream bug with Discord web application. status:confirmed Issues that could be reproduced status:patch-released Patched in current stable release type:bug Something isn't working

Comments

@TheTrio
Copy link

TheTrio commented Jun 19, 2022

Aknowledgements

  • I have checked that there's no other issue describing the same or
    similar problem that I currently have, regardless if it has been
    closed or open.

  • I can confirm that this is not an issue with the Discord website,
    but it is a problem specific to the WebCord itself.

  • I have tried running the build from the master branch and it does
    not have any fixes implemented according to my issue.

  • My issue describes one of the unstable and/or not fully implemented
    features.

  • I have found a workaround to mitigate or temporarily fix this issue
    (please write it in Additional context section).

Operating System / Platform

🐧️ Linux

Operating system architecture

x64 (64-bit Intel/AMD)

Electron version

v19.0.1

Application version

v3.2.0

Bug description

I'm unable to paste an image from the clipboard when using the keyboard shortcut(ctrl + v). However, right clicking and choosing "paste" does work.

To reproduce:

  1. Copy an image from your browser.
  2. Try pressing ctrl+v in the text box. Nothing happens
  3. Then right click and click on paste. This time the image gets uploaded
  4. Now press ctrl+v again. Somehow the shortcut works this time.

Additional context

Peek.2022-06-20.01-38.mp4
@TheTrio TheTrio added the type:bug Something isn't working label Jun 19, 2022
@SpacingBat3
Copy link
Owner

SpacingBat3 commented Jun 19, 2022

It it an Electron bug, quite known and old. The cause of it is that when content in the clipboard has two types (e.g. HTML=<img src="..."/> and PNG=Buffer<89 50 4E 47...>) – which funnily happens at copying images and trying to directly paste them into the WebCord. The workaround I've discovered only works with mouse context menu, the CTRL+V shortcut seems to be internally interpreted by the Electron/Chromium itself and can't be really replaced or handled.

So, until Electron development team won't fix it or Discord if they could somehow handle the different clipboard types and convert them to what they need (e.g. HTML to raw IMG or URL), I doubt I will fix it.

And even if the paste in right-click context menu is still working, I'm still unsure about its current implementation, as it modifies the clipboard content. What it does is something as follows:

  1. Read clipboard content.
  2. Determine whenever it has two, potentially conflicting types.
  3. Replace the clipboard content (i.e copy it again) with the one that has only one type.
  4. Paste it.

It does not revert the changes, I believe I couldn't find a way to do this. Maybe I will take a look on that again?

@SpacingBat3 SpacingBat3 closed this as not planned Won't fix, can't repro, duplicate, stale Jun 19, 2022
@SpacingBat3 SpacingBat3 added status:wontfix This will not be worked on status:confirmed Issues that could be reproduced labels Jun 19, 2022
@TheTrio
Copy link
Author

TheTrio commented Jun 19, 2022

Ah I see. Thanks for the explanation.

Although I wonder why pasting images in the official discord client works if it's an issue with electron.

@SpacingBat3
Copy link
Owner

Ah I see. Thanks for the explanation.

Although I wonder why pasting images in the official discord client works if it's an issue with electron.

Hmm, I guess they are aware of this bug and have a direct access to the clipboard? But if so, maybe there's a way to actually overwrite CTRL+V? I'll take a look on this, maybe reopen if there will be any chance to workaround CTRL+V as well...

@SpacingBat3
Copy link
Owner

Actually, this seems to be a Discord Web bug, I can even reproduce it in Chromium – it occurs for images copied between different browser engines. My guesses are it won't work as well when you would try to copy an image from Chromium and paste it in Discord Web launched in Firefox. And there's a way to actually fetch image from clipboard without any workarounds, both in WebCord and Chromium – just Discord does that the wrong way. I guess they can actually read the clipboard using the Electron clipboard API in their own Electron client, but in browser they use one of the Web APIs which somehow fails to get a tray content and/or handle it properly.

So, you should definitely report that to Discord developers, it's not my fault – even when WebCord actually does some weird workarounds that seems to kinda succeed where it should fail.

Anyway, I still implemented a better workaround, which actually does not modify the tray content (it preserves all of its types) and still works with CTRL+V. It works now in two processes:

Preload:

  1. Add new listener to the paste event (watches entire document).
  2. If content of the tray is broken:
    • (somehow) fix it,
    • stop event propagation (prevent any further events from execution),
    • send IPC message to main to re-emit paste event.
  3. Otherwise, do nothing and allow Discord to handle paste.

Main:

  1. Add new IPC listener for paste-workaround channel.
  2. When there will be any incoming message in paste-workaround, emit paste in current webContents.

See commit c3c8b16 for the actual implementation.

@SpacingBat3 SpacingBat3 added info:discord-web An upstream bug with Discord web application. and removed status:wontfix This will not be worked on labels Jun 20, 2022
@TheTrio
Copy link
Author

TheTrio commented Jun 20, 2022

Great! Thanks for the quick turnaround.

Is there any way I can try this locally without having to build from source?

@SpacingBat3
Copy link
Owner

Great! Thanks for the quick turnaround.

Is there any way I can try this locally without having to build from source?

It will be in the next app release (v3.3.0), that I plan shedule to build today.

@SpacingBat3 SpacingBat3 added the status:patch-released Patched in current stable release label Jun 20, 2022
@SpacingBat3 SpacingBat3 removed their assignment Jun 20, 2022
@TheTrio
Copy link
Author

TheTrio commented Jun 20, 2022

So I should probably open a new issue for this, but just in case its me who's doing something wrong, I'll ask here first.

Running the latest app image gives me the following error

image

/tmp/.mount_WebCorGCZ75f/usr/bin//../lib/webcord/webcord: error while loading shared libraries: libffmpeg.so: cannot open shared object file: No such file or directory

Any ideas?

@SpacingBat3
Copy link
Owner

So I should probably open a new issue for this, but just in case its me who's doing something wrong, I'll ask here first.

Running the latest app image gives me the following error

image

/tmp/.mount_WebCorGCZ75f/usr/bin//../lib/webcord/webcord: error while loading shared libraries: libffmpeg.so: cannot open shared object file: No such file or directory

Any ideas?

For some reason, the entire AppImage seems to be corrupted. IDK how that happened, I've generated the AppImage on my side and it seems to be alright. I feel that might be a bug with @reforged/maker-appimage, in which case, you should open an new issue on my Reforged GitHub repository.

@mackdroid
Copy link

Im having the exact same issue on flatpak version, unsure if i should create a seperate issue for this


WebCord - A Discord and Fosscord web-based client made with the electron

          ID: io.github.spacingbat3.webcord
         Ref: app/io.github.spacingbat3.webcord/x86_64/stable
        Arch: x86_64
      Branch: stable
     Version: 3.7.1
     License: MIT
      Origin: flathub
  Collection: org.flathub.Stable
Installation: system
   Installed: 243.8 MB
     Runtime: org.freedesktop.Platform/x86_64/21.08
         Sdk: org.freedesktop.Sdk/x86_64/21.08

      Commit: 8fba43c5961fdc5ae444daa619e94350eca963189bac85a0f178012317bde60f
      Parent: 1969fab39ee17125e2ca2e6a26059ec87f3b24c43474a965a4472fc21fdd5645
     Subject: Use --appimage-extract rather than unappimage (8c767c91)
out.mp4

@SpacingBat3
Copy link
Owner

SpacingBat3 commented Aug 24, 2022

Im having the exact same issue on flatpak version, unsure if i should create a seperate issue for this


WebCord - A Discord and Fosscord web-based client made with the electron

          ID: io.github.spacingbat3.webcord
         Ref: app/io.github.spacingbat3.webcord/x86_64/stable
        Arch: x86_64
      Branch: stable
     Version: 3.7.1
     License: MIT
      Origin: flathub
  Collection: org.flathub.Stable
Installation: system
   Installed: 243.8 MB
     Runtime: org.freedesktop.Platform/x86_64/21.08
         Sdk: org.freedesktop.Sdk/x86_64/21.08

      Commit: 8fba43c5961fdc5ae444daa619e94350eca963189bac85a0f178012317bde60f
      Parent: 1969fab39ee17125e2ca2e6a26059ec87f3b24c43474a965a4472fc21fdd5645
     Subject: Use --appimage-extract rather than unappimage (8c767c91)

out.mp4

I probably won't solve it through. There's a dirty workaround involved to make it functional and it is basically an issue with copying images between the browsers different browser engines.

Also flatpaks aren't officially supported yet. Try native package instead to see if the bug is reproducible without sandboxing.

@SpacingBat3
Copy link
Owner

As a side note, I still don't know why this issue exactly happens and how to exactly test if workaround needs to be applied. But testing on my side, it still works for me on 20.x.y so Electron did not broke it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
info:discord-web An upstream bug with Discord web application. status:confirmed Issues that could be reproduced status:patch-released Patched in current stable release type:bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants