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

yy doesn't work on HTTP sites in Firefox #4572

Open
leoheitmannruiz opened this issue Nov 16, 2024 · 9 comments
Open

yy doesn't work on HTTP sites in Firefox #4572

leoheitmannruiz opened this issue Nov 16, 2024 · 9 comments

Comments

@leoheitmannruiz
Copy link
Contributor

To Reproduce

  1. http://n-gate.com
  2. yy

Browser and Vimium version

Firefox 132.0.2
Vimium 2.1.2

@philg-dev
Copy link

philg-dev commented Nov 16, 2024

It works perfectly fine on my end on the given website.

I'm also on Firefox 132.0.2 and Vimium 2.1.2

Edit:
Sorry, it actually didn't seem to copy the link, despite the fact that Vimium showed the little "toast" tooltip in the bottom right claiming that it would have yanked the URL.

@leoheitmannruiz
Copy link
Contributor Author

Ah ok, thanks though! I was pretty spooked out for a second there :)

@leoheitmannruiz
Copy link
Contributor Author

I took a quick look at the code and I feel like it might be a Firefox bug?

Probably not though.

But, it seems that yy basically just calls tab.url? And, it works in Chromium and on HTTPS sites in Firefox.

Could it be that Vimium somehow has less privileges on HTTP sites or something?

Any ideas? What do you think?

@philg-dev
Copy link

From what I've seen in the code and the "toast-notification" in the bottom, the problem is not getting the URL. The URL is properly shown in the toast notification. The problem seems to be that it's not being copied to clipboard properly.

I'm not super familiar with the code either though, so I can't really tell right now.
From what I've seen so far the actual copying to clipboard is handled in an iframe, which is referred to as hudUI in hud.js. This seems to get certain permissions in the allow for non-Firefox browsers.

What I've seen in the console when trying to yy on the website you've provided is the following error though:

18:09:19.612 Uncaught (in promise) TypeError: navigator.clipboard is undefined
    copyToClipboard moz-extension://792162ca-50cd-416e-a4b0-6c8d954d80c6/pages/hud.js:172
    setTimeout handler*setTimeout moz-extension://792162ca-50cd-416e-a4b0-6c8d954d80c6/lib/utils.js:190
    copyToClipboard moz-extension://792162ca-50cd-416e-a4b0-6c8d954d80c6/pages/hud.js:164
    <anonymous> moz-extension://792162ca-50cd-416e-a4b0-6c8d954d80c6/pages/hud.js:202
    onmessage moz-extension://792162ca-50cd-416e-a4b0-6c8d954d80c6/pages/ui_component_server.js:26
hud.js:172:7
    copyToClipboard moz-extension://792162ca-50cd-416e-a4b0-6c8d954d80c6/pages/hud.js:172
    (Async: setTimeout handler)
    setTimeout moz-extension://792162ca-50cd-416e-a4b0-6c8d954d80c6/lib/utils.js:190
    copyToClipboard moz-extension://792162ca-50cd-416e-a4b0-6c8d954d80c6/pages/hud.js:164
    <anonymous> moz-extension://792162ca-50cd-416e-a4b0-6c8d954d80c6/pages/hud.js:202
    AsyncFunctionNext self-hosted:800
    (Async: async)
    onmessage moz-extension://792162ca-50cd-416e-a4b0-6c8d954d80c6/pages/ui_component_server.js:26

So something's definitely going wrong here. Maybe it is some kind of permission / security policy that prevents the relevant Vimium components to act properly.

@leoheitmannruiz
Copy link
Contributor Author

As you can tell, I'm quite ignorant :)

the problem is not getting the URL. The URL is properly shown in the toast notification

This I should have noticed though :))

Thanks a lot for taking a look!!

@philg-dev
Copy link

So the relevant API that's causing the error is Navigator.clipboard. According to the MDN, this is only available in secure contexts (HTTPS).

https://developer.mozilla.org/en-US/docs/Web/API/Navigator/clipboard

However, I did try this in Chromium as well and it just worked with no error.
Maybe this code snippet from content_scripts/hud.js makes this possible in Chromium based browsers?

      // Allow to access to the clipboard through iframes.
      // This is only valid/necessary for Chrome. Firefox will show this console warning:
      // 'Feature Policy: Skipping unsupported feature name "clipboard-read"'
      if (!Utils.isFirefox()) {
        this.hudUI.iframeElement.allow = "clipboard-read; clipboard-write";

According to the Browser Compatibility table for the Permissions API, the feature clipboard-read and clipboard-write permissions are flagged as experimental and currently not available in Firefox. Unless this compatibility data is outdated, I don't think there's much that can be done about it.

https://developer.mozilla.org/en-US/docs/Web/API/Permissions_API#browser_compatibility

@philc
Copy link
Owner

philc commented Nov 16, 2024

Nice investigation @philg-dev. If there is no workaround, it would be nice if Vimium can show a warning in its heads up display rather than silently fail to write to the clipboard.

@leoheitmannruiz
Copy link
Contributor Author

Is the fact that yy seems to work fine on HTTP sites using https://github.com/gdh1995/vimium-c of any help?

@philg-dev
Copy link

philg-dev commented Nov 17, 2024

From what I'm seeing in the code of this "fork", it looks like they're using a fallback mechanism to handle clipboard actions via the old and deprecated way document.execCommand("copy") if navigator.clipboard is not available.

I'm not very well versed in TypeScript yet, so the other project is pretty hard to read for me, so I might be wrong.

https://developer.mozilla.org/en-US/docs/Mozilla/Add-ons/WebExtensions/Interact_with_the_clipboard

So it seems like theoretically we could also use this method, but the fact that it involves deprecated functions makes it seem like a pretty bad idea to implement a workaround like that.

@philc I did implement a simple error handling that intercepts at the start of the central copy & paste functions that are used by all other Vimium actions related to the clipboard. I'm showing a HUD tooltip / toast notification for 2 seconds that just says:

"Clipboard actions are unavailable on HTTP-only sites in your browser."

I've tested it in Firefox and Chromium locally and it seems to work just fine. (Edit: in Chromium clipboard works on HTTP, it doesn't show the new error.)
If you want me to, I can create a pull request and link it to this issue.

Edit: I've noticed that the tooltip is a bit too long to be fully displayed. If you have any feedback on what else it should say, feel free to let me know.

This is what it looks like on my end right now:
image

philg-dev added a commit to philg-dev/vimium that referenced this issue Nov 18, 2024
- checking if navigator.clipboard is available
- showing warning HUD message when clipboard unavailable
- affects HTTP-only sites in non-Chromium browsers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants