I have an extension working on Chrome and Firefox. I recently used the converter to create a Safari Web Extension. That worked really well and the extension mostly works in Safari.
However I am seeing one bug:
When the user invoke the extension popup menu I send a message using chrome.tabs.sendMessage to the active tab. In the case where I have no content script for this page URL there is no listener for the message.
In Chrome and Firefox I get a response and chrome.runtime.lastError is set so I can display a default popup menu. But in Safari I get no error or response.
Post
Replies
Boosts
Views
Activity
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.