bhadaway/canonical

Copy canonical to clipboard

Closed this issue · 4 comments

Would it be possible to add a feature to copy the canonical link of the page to the clipboard?

I found myself on a nasty website where I could click the canonical link but it would then redirect me to a page with added parameters − however I want to save the canonical URLs, so I had to 1) click the canonical icon to get rid of most of the garbage, 2) select which part of the address bar to copy/paste, 3) ctrl + c.

I think this feature would be useful if you’re already on a non-canonical page, but if you want to save or share it for whatever reason, and want to use the canonical link for that.

I think this could be pretty easy to implement:

  • just requires adding the clipboardWrite permission I believe
  • either with shift + click on the icon, or with an (optional) keyboard shortcut
  • then a function that simply does Clipboard.writeText(), e.g.: navigator.clipboard.writeText(canonicalUrl)

That's just a one-way permission, right? To add something to the clipboard, but we wouldn't have to grant the add-on access to what's already in someone's clipboard? Privacy/security is always a concern for me, and keeping things simple is the best policy where that's concerned.

What about adding "Copy" to the icon context menu when right-clicking on it? Or perhaps that's a reserved space for official Firefox options only?

Yes it’s a separate permission from clipboardRead. I’ve never had to add options to a pageAction context menu, but it may be possible. The pageAction listener doc says:

To define a right-click action, use the contextMenus API with the "page_action" context type.

If you want to try submitting this idea as a pull request, I'll be happy to review and consider it.