Skip to content

Test navigator.clipboard defined before accessing #1

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

Xadiant
Copy link

@Xadiant Xadiant commented Jul 19, 2023

Most browsers now require that the the web page is "Secure" or else they do not allow access to the clipboard, this includes navigator.clipboard. I noticed that in my application that when I access my app locally (where https is not applied yet) invoking the copy methods results in an exception where "writeText" does not exist in "undefined".

To smooth over this, I added a test for the clipboard existing before calling the method.

If you agree with this idea, I imagine we will want to output an error when this if check fails, or maybe modify the function signature to return a variable indicating success.

@slowriot
Copy link
Member

slowriot commented Nov 8, 2024

Thanks for the contribution. I think it needs a bit more, as currently it's just suppressing the error silently. Ideally, as you say the function should have some way of reporting the error - returning bool instead of void so developers can identify if the operation failed, along with a console log message explaining why for the user's benefit.

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.

2 participants