Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Safari share links aren't copied to clipboard #15

Open
maxwofford opened this issue Jan 25, 2022 · 18 comments · Fixed by #34 or #67
Open

Safari share links aren't copied to clipboard #15

maxwofford opened this issue Jan 25, 2022 · 18 comments · Fixed by #34 or #67
Labels
bug Something isn't working good first issue Good for newcomers low priority

Comments

@maxwofford
Copy link
Member

No description provided.

@maxwofford maxwofford added bug Something isn't working good first issue Good for newcomers labels Jan 26, 2022
@maxwofford
Copy link
Member Author

Screen Shot 2022-01-26 at 10 13 50

The share link (1) button should create a share link and add it to the user's clipboard. On safari it notifies the user that the link was added to their clipboard (2), but when pasting the share link doesn't come out (whatever was previously in the clipboard does).

@maxwofford
Copy link
Member Author

Forgot to mention, this works in FF & Chrome. This is probably the related code: https://github.com/hackclub/game-lab/blob/0dcd140b1814897bd1d425f62ca8c4273999fcc7/dispatch.js#L7-L14

@maxwofford
Copy link
Member Author

Now running into this on FF
Screen Shot 2022-01-26 at 18 37 43

@cjdenio
Copy link
Member

cjdenio commented Jan 27, 2022

Yeah, most browsers only let you copy to the clipboard as a direct result of user interaction.

Chrome lets you explicitly request permission via the Permissions API, but Firefox and Safari don't support it yet

@zachlatta
Copy link
Member

@zachlatta
Copy link
Member

So I've done a little research here, and it turns out the issue is that Safari has some security policies in place that prevent any clipboard commenting to happen unless a DOM event is in scope (so to ensure that a DOM event triggered the copy to clipboard).

I am not sure what the appropriate way of passing the DOM event to the copy function would be with the architecture of Game Lab. @leomcelroy / @cedric-h: this might be a good thing for one of you to handle.

I've tried using various 3rd party clipboard libraries and none of the ones I've tried work, so I'm pretty sure it's down to the DOM event thing.

It looks like this might be a very recent thing. There are some other repos with this issue popping up, notably apache/superset#18154.

@maxwofford
Copy link
Member Author

Copying doesn't work in any browser for me. Reopening

@maxwofford maxwofford reopened this Feb 23, 2022
@maxwofford
Copy link
Member Author

The diff for https://github.com/hackclub/gamelab/pull/67/files doesn't make sense to me– seems like something was mis-commited or something. If I'm reading it right it seems like it removes copy logic.

@faisalsayed10
Copy link
Member

@maxwofford @leomcelroy this is my main commit - a7618a3 (#67)
i think something has went wrong, and we've mis-commited something

@faisalsayed10
Copy link
Member

also @leomcelroy this commit of yours kinda reverted my commit b50ee51 (#67)

@maxwofford
Copy link
Member Author

Something that might help for fixing this issue: saves are deterministic. Even before we make a post request, we know the share link will be gamelab.hackclub.com/?id=MD5 where MD5 is the hash of the game state

CC'ing @cedric-h who can correct me if I said something wrong.

@isabellalacerda
Copy link

Copying also doesn't work in any browser for me. How can i fix this?

image
image

@maxwofford
Copy link
Member Author

Can you share the URL that screenshot was taken at? It doesn't look like a part of the gamelab interface

@Peiprjs
Copy link
Member

Peiprjs commented Aug 27, 2022

You can copy the URL from the console. Otherwise, it only copies some Javascript

@alhardwarehyde
Copy link
Contributor

@grymmy can you reproduce this?

@alhardwarehyde
Copy link
Contributor

Ignore my ask. This is an ongoing issue

@alhardwarehyde alhardwarehyde removed the good first issue Good for newcomers label Mar 7, 2023
@alhardwarehyde alhardwarehyde moved this to Todo (queue) in Sprig Mar 7, 2023
@grymmy grymmy added the good first issue Good for newcomers label Dec 15, 2023
@grymmy
Copy link
Contributor

grymmy commented Dec 15, 2023

An update on this issue - while the editor still does not correctly copy to the clipboard on safari, it shows a high-quality error and feedback to the user when it files to copy to the clipboard. As a result, I believe this is quite low priority - but I've confirmed yes, still a present bug

@maxwofford
Copy link
Member Author

maxwofford commented Apr 11, 2024

I believe the filenaming is deterministic (ie. even before you save, we know your share link will be https://sprig.hackclub.com/share/XXXXX and XXXXX is a known value), so you can copy to clipboard immediately to fix this error.

EDIT: safari only lets access to the clipboard immediately in the context of an event– ie. a button click. They don’t allow it anywhere else (ie. the async context of a then after a fetch). The initial implementation of saving accounted for this by giving a deterministic share link so we could copy the link immediately instead of waiting for the fetch to finish. This may have changed since we launched. https://wolfgangrittner.dev/how-to-use-clipboard-api-in-safari/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers low priority
Projects
Status: Todo (queue)
Development

Successfully merging a pull request may close this issue.

9 participants