jspaint icon indicating copy to clipboard operation
jspaint copied to clipboard

Internal copy not working on macOS Safari

Open Alyaron opened this issue 1 year ago • 1 comments
trafficstars

Thanks for the great project! The readme describes the following known limitation:

Full clipboard support in the web app requires a browser supporting the Async Clipboard API w/ Images, namely Chrome 76+ at the time of writing. In other browsers you can still copy with Ctrl+C, cut with Ctrl+X, and paste with Ctrl+V, but data copied from JS Paint can only be pasted into other instances of JS Paint. External images can be pasted in.

On Safari on macOS,

  • Pasting an external image works as described,
  • Copying selection (both Ctrl+C and the menu entry) displays the following error though:
Failed to copy to the clipboard
NotAllowedError: The request is not allowed by the user agent or the platform in the current context, possibly because the user denied permission.
write@[native code]
@https://jspaint.app/src/functions.js:2338:30
sanity_check_blob@https://jspaint.app/src/functions.js:3772:17
@https://jspaint.app/src/functions.js:2337:21

And indeed it doesn't copy anything, as the command Paste will paste whatever was in the clipboard before.

What I would have expected by reading the readme, is to still be able to copy internally to JS Paint, in order to paste to another part of the same image within JS Paint.

I saw other clipboard issues being reported, but not this one, would you be able to help me figure out if it's a bug, a limitation, or myself doing something wrong? Thanks again.

Alyaron avatar Mar 19 '24 22:03 Alyaron

I believe what's happening here is JS Paint is only falling back if the browser doesn't report support for the Async Clipboard API, but Safari is reporting support even though it doesn't support copying images to the clipboard, only text. (That, or else the feature is disabled as some sort of security measure.)

It probably needs to use the fall back in the case that it gets an error, not just if the browser doesn't say it supports the API.

Relevant code: https://github.com/1j01/jspaint/blob/da994966ec2231743867f232d8e1fb334071b512/src/functions.js#L2575-L2597 Related issues:

  • https://github.com/1j01/jspaint/issues/241
  • https://github.com/1j01/jspaint/issues/286

1j01 avatar May 31 '24 00:05 1j01