flynt icon indicating copy to clipboard operation
flynt copied to clipboard

Fixing use of `execCommand('copy')`

Open gRoberts84 opened this issue 10 months ago • 1 comments

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').

gRoberts84 avatar Apr 23 '24 13:04 gRoberts84

@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.

timohubois avatar Apr 26 '24 15:04 timohubois

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.

gRoberts84 avatar May 21 '24 16:05 gRoberts84

@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?

timohubois avatar May 21 '24 20:05 timohubois

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

gRoberts84 avatar May 24 '24 09:05 gRoberts84