Handling exceptions for writeText()
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 42/100
- Tipo di issue
- Bug
- Chiarezza
- Abbastanza chiara
- Stato di attività
- Ferma
- Stack tecnologico
- javascript
Direzione di ricerca
Riproducete il problema con gli esempi HTML forniti, confrontando il comando writeText() con la chiamata a navigator.clipboard.writeText(). Tracciate il modo in cui la promise degli appunti rifiutata viene gestita da catch e on exception, quindi verificate che l'errore raggiunga il gestore senza segnalare il successo né registrare un rifiuto non gestito.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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:
- Lingua principale
- JavaScript
- Stelle
- 3.8k
- Fork
- 171
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di bigskysoftware/_hyperscript
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
bigskysoftware/_hyperscript#688 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
bigskysoftware/_hyperscript#678 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
bigskysoftware/_hyperscript#676 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
bigskysoftware/_hyperscript#695 ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 62/100
bigskysoftware/_hyperscript#687 ·
Tutte le issue di bigskysoftware/_hyperscript
Issue simili
-
bug
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
apache/cloudstack#14222 ·
-
Browser Waiting for: Product Owner
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
getsentry/sentry-javascript#24577 · 1 commento ·
-
curation good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
amponce/archive-movie-browser#186 ·
-
light
Difficoltà 2/5 1-3 ore Idoneità per principianti 85/100
aemdemos/patients-stryker#253 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
clerk/javascript#9852 ·