philc / vimium

The hacker's browser.
https://chrome.google.com/webstore/detail/vimium/dbepggeogbaibhgnhhndojpepiihcmeb
MIT License
23.52k stars 2.49k forks source link

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

Open leoheitmannruiz opened 3 hours ago

leoheitmannruiz commented 3 hours ago

To Reproduce

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

Browser and Vimium version

Firefox 132.0.2 Vimium 2.1.2

philg-dev commented 3 hours ago

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 commented 3 hours ago

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

leoheitmannruiz commented 2 hours ago

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 commented 2 hours ago

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 commented 2 hours ago

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 commented 1 hour ago

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 commented 58 minutes ago

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.