ssborbis / ContextSearch-web-ext

Search engine manager for modern browsers
351 stars 37 forks source link

"Copy to clipboard" tool doesn't work as expected in some cases. #688

Open Polisson opened 7 months ago

Polisson commented 7 months ago

I came here because looking for the ability to copy text from a site also with formatting (so copying a link hidden in text, allows further pasting such link). Thought that it didn't work at all, but after test I've realized that sometimes it does.

Behavior of Copyt tool is like: Browser secure (https) insecure (http)
Chrome-based raw text properly copied text + formatting
Firefox-based raw text empty clipboard

Standard OS copying with Ctrl+C acts like expected (full content with formatting).

OS: Windows 10 22H2, KDE Neon browser: Waterfox G6.0.9 (64-bit) (but Firefox acts the same) Vivaldi 6.5.3206.63 (Stable channel) (64-bit) Chrome 123.0.6312.59 (Official Build) (64-bit) Pasting content to e.g. MS Word 365, Libre Office 24.2.2

I desperately need such a feature, but I'm in love with this extension, so reported this issue and would rather not switch to Swift Selection Search (FF addon) which supports that.

ssborbis commented 7 months ago

If I remember correctly, some clipboard features only work properly on https websites, per the browser's security policies. Do you have a particular website or link I can test on?

Polisson commented 7 months ago

I've found this issue in my corporate environment (intranet site) but before posting this bug I was playing on sites like http://w3.org/, http://gnu.org/, http://nginx.org/ and many others which still use http protocol (be aware that modern browsers prevent browsing non-secured sites, so often redirect happens, like all I've mentioned above, so you have to properly set browser to disable redirecting). Also, one Polish site is served only without SSL: http://swiat-kamienia.pl/en/

ssborbis commented 7 months ago

I believe I have a fix in the master branch. If you're in a position to test, give it a try. Otherwise, the fix will be in the next release.

Polisson commented 7 months ago

Hi, I've just tested on Chromium-based browser (Brave on Ubuntu) and it seems to me that my issue isn't resolved and even regression occurred. Copy tool, still gather to clipboard only raw text (now also on insecure websites). The autocopy feature isn't what I was looking for (but that seems You worked on last commit). Anyway, thanks for info.

ssborbis commented 7 months ago

Hmm. What I had seen was that the copy tool hanged on insecure websites ( spinner.gif, no copy). I had only been testing on Firefox. I'll see what is happening on chrome.

ssborbis commented 7 months ago

So the issue you're having is the copy tool is now only copying raw text on insecure sites, and you're looking to copy formatted links, correct? For my own testing, I assume pasting the clipboard contents into a generic word processor will show whether the link formatting is kept? What app are you pasting into?

Polisson commented 7 months ago

Hmm. What I had seen was that the copy tool hanged on insecure websites ( spinner.gif, no copy). I had only been testing on Firefox. I'll see what is happening on chrome.

Yes, I've observed that also, but "the endless spinner" on firefox+insecured was rather difficult to trigger, the result was only an empty clipboard.

So the issue you're having is the copy tool is now only copying raw text on insecure sites, and you're looking to copy formatted links, correct?

Yes, I need to copy formatted links. But to be exact - copy tool is now only copying raw text on secure sites.

For my own testing, I assume pasting the clipboard contents into a generic word processor will show whether the link formatting is kept? What app are you pasting into?

Yeah, if clipboard content is complete, you will see it on pasting to any app which is aware of data types in clipboard. Generally, I need to paste formatted content to word processors like MS Word on Windows and LibreOffice on Linux.

To clarify: most of the sites I work on, are secured and I can't copy formatted content with Copy tool on them. However, I've noticed that on unsecured pages, in Chromium-based browsers, the tool works perfectly, but on Firefox it doesn't work at all. PS: I'm just enhancing first post to better clarification ;-)

ssborbis commented 7 months ago

I think this is due to the depreciated javascript document.execCommand("copy") function being used as a fallback on unsecured websites. I had no idea there was functionality being lost by using the preferred Clipboard API in web extensions. I'm toying with a setting that forces the copy commands to use the depreciated function, but I can't guarantee it will work with a particular browser. If you're able to sideload this addon, I'll get you a .zip of a test branch with the additional setting. I had some luck pasting into LibreOffice, but inconsistent results. Even the depreciated command doesn't seem to carry the full formatting in the way a Ctrl-C copy would.

Polisson commented 6 months ago

OK, actually my profession is software testing (admittedly, I test devices with embedded systems, but when I come across a bug I can't resist from further testing ;-)) If I would have difficulties with sideloading, I'll provide feedback. So give it to me 😄 The Selection Swift Search addon I mentioned in first post can gather the formatted text (don't know if complete, but partially for sure). But it is abandoned now and for Firefox only. I don't know such possibilities in the chromium world.

ssborbis commented 6 months ago

Fortunately, sideloading in chromium-based is pretty simple.

Oh, are you highlighting the links to copy them or just right-clicking? That will make a difference in the code I'm testing.

ssborbis commented 6 months ago

Using chromium, I have these results with the new setting forcing the depreciated copy function

  1. Ctrl-C
  2. setting off
  3. setting on

image

It looks like there is at least some formatting going on.

Polisson commented 6 months ago

Yeah! I can confirm your observations. I've just tested on Brave browser. Same as your effect: with copyUseDepreciatedExecCommand parameter turned on, links are followable, fonts have size and style preserved, but colors, font types aren't. That would be sufficient for me. But will it be future-proof (as it is deprecated in JS)?

ssborbis commented 6 months ago

But will it be future-proof (as it is deprecated in JS)?

Certainly not, but the execCommand('copy') has been depreciated for years and is still included with all major browsers.

ssborbis commented 6 months ago

Changes are live in 1.46.25 in AMO and chromestore