fix(useClipboard): unhandled rejection on read permission prompt #4615
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
fixes #123
).Description
When
options.read === true
and the'clipboard-read'
permission value is'prompt'
, thusisAllowed()
returnstrue
and an attempt to use the Clipboard API is made, before the user can press either Allow or Deny, thePromise
returned bynavigator.clipboard.readText()
can be rejected with aNotAllowedError
. This was covered in #4512, but a wrong syntax combination was used, consequently, the fallback tolegacyRead()
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 toPromise.catch()
for its advantages and by analogy tocopy()
from the same PR.