Handling exceptions for writeText()
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 42/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- javascript
Research direction
Reproduce the issue with the supplied HTML examples, comparing the writeText() command with call navigator.clipboard.writeText(). Trace how the rejected clipboard promise is handled by catch and on exception, then verify that the error reaches the handler without reporting success or logging an unhandled rejection.
Written by the indexing model from the issue text.
Description
I'm unable to handle exception while a coping text to a clipboard idiomatically. Maybe it's not the only place for such behavior but it's the only one I've found.
I'm using qutebrowser and I've blocked programmatic access to a clipboard for websites.
Unfortunately, I don't know how to block access the same way for other browses =\
Use case: I want to show a notification that user has successfully copied text to the clipboard or if there is an error. To do so I have to handle exception that writeText() might throw.
I expect the following code to work:
<script src="https://unpkg.com/hyperscript.org@0.9.12"></script>
<button
_="on click
writeText('text to copy') into the navigator's clipboard
then put 'Success' into the next <output/>
catch e
put `Error: $e` into the next <output/>">
Copy
</button>
<output>--</output>
Output shows Success and console logs Uncaught (in promise) DOMException: Write permission denied.. catch doesn't seem to work.
There is another way to catch exceptions for an element (on exception):
<script src="https://unpkg.com/hyperscript.org@0.9.12"></script>
<button
_="on click
writeText('text to copy') into the navigator's clipboard
then put 'Success' into the next <output/>
on exception(e)
put `Error: $e` into the next <output/>">
Copy
</button>
<output>--</output>
The same result: output shows Success and console logs Uncaught (in promise) DOMException: Write permission denied..
Feels like exception isn't related to the element in any way.
Sanity check
Just to make sure that exceptions are catchable:
<script src="https://unpkg.com/hyperscript.org@0.9.12"></script>
<button
_="on click
throw 'I am thrown manually'
then put 'Success' into the next <output/>
catch e
put `Error: $e` into the next <output/>">
Copy
</button>
<output>--</output>
Shows Error: I am thrown manually in output and console is clean.
<script src="https://unpkg.com/hyperscript.org@0.9.12"></script>
<button
_="on click
throw 'I am thrown manually'
then put 'Success' into the next <output/>
on exception(e)
put `Error: $e` into the next <output/>">
Copy
</button>
<output>--</output>
This one is interesting. It shows Error: in output and picrelated in console
Workaround
I've managed to get it working by calling writeText() in a more traditional way:
<script src="https://unpkg.com/hyperscript.org@0.9.12"></script>
<button
_="on click
call navigator.clipboard.writeText('text to copy')
then put 'Success' into the next <output/>
catch e
put `Error: $e` into the next <output/>">
Copy
</button>
<output>--</output>
Output has Error: NotAllowedError: Write permission denied. and a clean console.
<script src="https://unpkg.com/hyperscript.org@0.9.12"></script>
<button
_="on click
call navigator.clipboard.writeText('text to copy')
then put 'Success' into the next <output/>
on exception(e)
put `Error: $e` into the next <output/>">
Copy
</button>
<output>--</output>
This one behaves the same way it does in sanity check. In catches the exception but error is empty while console has the following:
- Dominant language
- JavaScript
- Stars
- 3.8k
- Forks
- 171
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from bigskysoftware/_hyperscript
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
bigskysoftware/_hyperscript#688 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
bigskysoftware/_hyperscript#678 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
bigskysoftware/_hyperscript#676 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 68/100
bigskysoftware/_hyperscript#695 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 62/100
bigskysoftware/_hyperscript#687 ·
All issues in bigskysoftware/_hyperscript
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
HarperFast/skills#96 ·
-
[Block] Latest Posts [Type] Bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Automattic/studio#4908 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
sugarlabs/musicblocks#8847 ·