bigskysoftware / bigskysoftware/_hyperscript

Handling exceptions for writeText()

Đang mở
#565 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
JavaScript
Star
3.8k
Fork
171
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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

![image](https://github.com/user-attachments/assets/7c411767-d1ec-4a39-875f-ab1df4994397)

## 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:

![image](https://github.com/user-attachments/assets/12685deb-e38a-4166-b148-ec74e75804b9)

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Hướng nghiên cứu

Tái hiện vấn đề với các ví dụ HTML được cung cấp, so sánh lệnh writeText() với lời gọi navigator.clipboard.writeText(). Theo dõi cách promise clipboard bị từ chối được catch và on exception xử lý, sau đó xác minh rằng lỗi đến được handler mà không báo cáo thành công hoặc ghi log một unhandled rejection.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
javascript
Lĩnh vực
frontend, web-dev
Loại issue
Lỗi
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
42/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.