yorkxin / copy-as-markdown

A browser extension to copy tabs and links as Markdown
MIT License
546 stars 83 forks source link

Not Working when using keyboard shortcut #117

Closed cvladan closed 1 year ago

cvladan commented 1 year ago

I made a keyboard shortcut in Firefox so that Alt-C triggers "Current Tab Link" extension action. However, the extension often doesn't work in Firefox, that is, it works if you click on the icon but not if you use the keyboard shortcut.

  1. The keyboard shortcut doesn't work at all and works on mouse click.
    Example URL: https://support.mozilla.org/en-US/kb/manage-extension-shortcuts-firefox

  2. On my keyboard shortcut, a red cross appears over icon and it doesn't work, while it works on mouse click. It probably has to do with the fact that the site is not HTTPS, but I'm not sure.
    Example URL: http://secudream.com/product_17556.html

Based on example 2, I conclude that the extension IS triggered but doesn't execute correctly. Regardless, it's all very unreliable.

Environment

Browser: Firefox Dev 110 Operating System: Windows 11 System Language:English

martinvonwittich commented 1 year ago

I think I just encountered the same issue - usually the keyboard shortcut works fine, but on this URL it doesn't: http://michael.orlitzky.com/cves/cve-2018-6954.xhtml

Note that this is also unencrypted HTTP, like @cvladan's second example URL. The first example URL (support.mozilla.org) likely doesn't work because it is a restricted domain in Firefox (extensions.webextensions.restrictedDomains) which means that extensions aren't allowed to fiddle with it. This is to protect users from malware extensions which might attempt to block user access to Mozilla domains, so that users still can get help to clean the infection.

Manually clicking on the icon -> Current Tab Link works, but hitting the keyboard shortcut for current tab doesn't work, and shows the red cross error indicator on the icon.

The debugger prints the following error message to the console:

Error: content script failed: TypeError navigator.clipboard is undefined (method = navigator_api)
    writeUsingContentScript moz-extension://4b97863e-3d81-4115-a339-17ed2c19a8ac/dist/lib/clipboard-access.js:170
[background.js:208:13](moz-extension://4b97863e-3d81-4115-a339-17ed2c19a8ac/dist/background.js)
    <anonymous> moz-extension://4b97863e-3d81-4115-a339-17ed2c19a8ac/dist/background.js:208

Which apparently indicates that the Clipboard API isn't available on unencrypted sites.

yorkxin commented 1 year ago

Thanks for your feedback.

Thanks, @martinvonwittich for debugging the issue. It looks like that's what happened:

  1. The Clipboard API is not available on Mozilla's websites.
  2. The Clipboard API is not available on insecure websites.

In both cases, the md icon will show a red X icon. I understand not everyone is placing the extension's icon on the toolbar, so it is fair to say that it may 'silently fail'. I am still exploring options to display notifications while an error happens.

For now please allow me to close this issue since this is a behavior that cannot be controlled by extension developers.

cvladan commented 1 year ago

I've experimented with userscripts and it should work on HTTP sites