Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

fix(useClipboard): unhandled rejection on read permission prompt #4615

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

Merged
merged 1 commit into from
Feb 26, 2025

Conversation

Vitalis11
Copy link
Contributor

@Vitalis11 Vitalis11 commented Feb 19, 2025

Fallback to document.getSelection() on read permission prompt as intended instead of consuming NotAllowedError

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

Description

When options.read === true and the 'clipboard-read' permission value is 'prompt', thus isAllowed() returns true and an attempt to use the Clipboard API is made, before the user can press either Allow or Deny, the Promise returned by navigator.clipboard.readText() can be rejected with a NotAllowedError. This was covered in #4512, but a wrong syntax combination was used, consequently, the fallback to legacyRead() didn't happen, and an unhandled rejection with a NotAllowedError was generated in the console. This PR handles the rejection by falling back as intended.

Additional context

See reply to where this was introduced. Async/await is supported by addEventHandler() and was preferred to Promise.catch() for its advantages and by analogy to copy() from the same PR.

Fallback to document.getSelection() on read permission prompt as intended instead of consuming NotAllowedError
@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Feb 19, 2025
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Feb 20, 2025
@43081j 43081j added this pull request to the merge queue Feb 26, 2025
Merged via the queue into vueuse:main with commit a54c4b4 Feb 26, 2025
8 checks passed
@Vitalis11 Vitalis11 deleted the fix/useClipboard branch March 5, 2025 20:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm This PR has been approved by a maintainer size:XS This PR changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
Morty Proxy This is a proxified and sanitized view of the page, visit original site.