I'm porting an extension that works in Chrome and Firefox.
The MDN page here: https://developer.mozilla.org/en-US/docs/Web/API/Clipboard#clipboard_availability claims that this interface is supported in Safari.
But when I call it it throws an exception with no helpful information in the error object.
In Chrome and Firefox no special permissions are required to use clipboard write (at least on active pages). Is this permission needed in Safari?
I am calling it from a popup menu on an active page (where I have a content script and permissions).
Has anyone used navigator.clipboard.writeText in a Safari Web Extension? If so, did you have to request the permission in the manifest?
Update: I have tried adding the "clipboardWrite" permission to the manifest and it still fails in Safari [Version 15.0 (16612.1.29.41.4, 16612)]
Update2: I found this article which talks about the subject but doesn't give details on how to make it actually work: https://portswigger.net/daily-swig/new-safari-clipboard-api-includes-additional-browser-security-privacy-mechanisms
Update3: I found more info here: https://webkit.org/blog/10247/new-webkit-features-in-safari-13-1/ It says that the API "must be called within user gesture event handlers like pointerdown or pointerup, and only works for content served in a secure context (e.g. https://)"
That does not sound promising. My whole extension is for building citations which are copied to the clipboard. They a built procedurally when the user selects a menu item on the popup menu. I'm thinking I will have to scrap the port to Safari :(
It sounds like it may be possible using hacky solutions of creating a dummy element on a page and using execCommand('copy') which sounds horrible and not something that I want to pollute my extension with.
If anyone has any ideas on how to make it work please respond.