Skip to content

Conversation

TylerLeonhardt
Copy link
Member

@TylerLeonhardt TylerLeonhardt commented Dec 22, 2021

In Safari, it has the following note:

"The request to write to the clipboard must be triggered during a user gesture. A call to clipboard.write or clipboard.writeText outside the scope of a user gesture(such as "click" or "touch" event handlers) will result in the immediate rejection of the promise returned by the API call."

From: https://webkit.org/blog/10855/async-clipboard-api/

Since extensions run in a web worker, and handle gestures in an asynchronous way, they are not classified by Safari as "in response to a user gesture" and will reject.

This function sets up some handlers to work around that behavior by leveraging the ClipboardItem API that takes in a Promise:
https://developer.mozilla.org/en-US/docs/Web/API/ClipboardItem/ClipboardItem#parameters

This PR fixes #106997

@TylerLeonhardt TylerLeonhardt changed the title Workaround Safari clipboard behavior Workaround Safari clipboard.writeText behavior Dec 22, 2021
if (isSafari) {
this.logService.error(error);

return ''; // Safari does not seem to provide anyway to enable cipboard access (https://github.com/microsoft/vscode-internalbacklog/issues/2162#issuecomment-852042867)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Safari supports readText now so this does work now.

…xt return the promise DeferredPromise.complete returns
@jrieken jrieken added this to the January 2022 milestone Dec 23, 2021
@TylerLeonhardt TylerLeonhardt merged commit a6487c6 into main Dec 23, 2021
@TylerLeonhardt TylerLeonhardt deleted the joh/safariCopy branch December 23, 2021 14:45
@github-actions github-actions bot locked and limited conversation to collaborators Feb 6, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Clipboard API doesn’t work on Codespaces (using Safari)
4 participants