yorkxin / copy-as-markdown

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

Consider using Clipboard API where available (Chrome 66, Firefox 63) #66

Closed AlexVallat closed 5 years ago

AlexVallat commented 5 years ago

Clipboard.writeText is an API specifically for writing to the clipboard. It would avoid the need to create an invisible textarea and exec a copy command on it, and in Firefox would avoid the need for a content-script (as background scripts can use that API)

yorkxin commented 5 years ago

Hi there, sorry for super late response.

This API is available, but unfortunately Firefox and Chrome has different support on it.

Specifically, Chrome will check if the command is executed on a "focused document". So it's available in Content Script or Popup only (no Background Page).

You can see this file for details and workaround. https://github.com/chitsaou/copy-as-markdown/blob/master/src/background/clipboard-access.js

Cheers!