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

Fixing use of execCommand('copy') #551

Conversation

gRoberts84
Copy link

When using the Copy Link button on the Anchor component without navigator.clipboard support, it reverts to execCommand('copy') which requires the content to copy to be selected.

This PR adds code to ensure the link is selected before calling execCommand('copy').

Updated to select the anchor before calling execCommand.
@timohubois
Copy link
Contributor

timohubois commented Apr 26, 2024

@gRoberts84 many thanks for the pr. I took a short to can i use: https://caniuse.com/?search=navigator.clipboard

It seems that navigator.clipboard has widely support (95.37%; [04-26-2024]) which is pretty close to the the browserlist setting supports array-flat (96.82%; [04-26-2024]) inside the package.json.

Did you run in trouble with the current implementation at a specific browser? I am looking forward to learning more details.

@gRoberts84
Copy link
Author

Hi @timohubois

Apologies for the delay in getting back to you.

I had mistaken it only working over HTTPS as a bug but it had highlighted an issue where if navigator.clipboard isn't available for any reason (e.g. insecure local environment) then it tries to use execCommand('copy') without any text being selected, so it copies nothing.

Appreciate that under most circumstances, this won't be an issue but someone could come across it again on an insecure site.

@timohubois
Copy link
Contributor

@gRoberts84 many thanks for your feedback.

I think it's not a problem or a bug as this is the normal behavior of the "Navigator: clipboard property" and insecure connections are rather uncommon and an edge case these days in my opinion.

Would prefer to close this issue in relation to this. What do you think?

@gRoberts84
Copy link
Author

@timohubois appreciate your view on this and happy to close the PR.

@gRoberts84 gRoberts84 closed this May 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants