bigskysoftware / bigskysoftware/_hyperscript
Handling exceptions for writeText()
- Vorherrschende Sprache
- JavaScript
- Sterne
- 3.8k
- Forks
- 172
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Beschreibung
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:
```html
Copy
--
```
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`):
```html
Copy
--
```
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:
```html
Copy
--
```
Shows **Error: I am thrown manually** in output and console is clean.
```html
Copy
--
```
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:
```html
Copy
--
```
Output has **Error: NotAllowedError: Write permission denied.** and a clean console.
```html
Copy
--
```
This one behaves the same way it does in sanity check. In catches the exception but error is empty while console has the following:

Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Rechercherichtung
Reproduzieren Sie das Problem mit den bereitgestellten HTML-Beispielen, indem Sie den Befehl writeText() mit dem Aufruf von navigator.clipboard.writeText() vergleichen. Verfolgen Sie, wie das abgelehnte Clipboard-Promise von catch und on exception behandelt wird, und überprüfen Sie anschließend, dass der Fehler den Handler erreicht, ohne Erfolg zu melden oder eine unbehandelte Rejection zu protokollieren.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- javascript
- Bereich
- frontend, web-dev
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Veraltet
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 42/100