IdleDetector: start() method
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Experimental: This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
Note: This feature is available in Dedicated Web Workers.
Phương thức start() của giao diện IdleDetector trả về một Promise phân giải khi bộ phát hiện bắt đầu lắng nghe các thay đổi trong trạng thái rảnh rỗi của người dùng. Phương thức này nhận một đối tượng options tùy chọn với threshold tính bằng mili giây xác định thời gian không hoạt động cần báo cáo và signal cho AbortSignal để hủy bộ phát hiện rảnh rỗi.
Cú pháp
start()
start(options)
Tham số
optionsOptional-
Một đối tượng với các thuộc tính sau:
threshold-
Số mili giây rảnh rỗi tối thiểu trước khi bắt đầu báo cáo.
signal-
Tham chiếu đến một phiên bản
AbortSignalcho phép hủy phát hiện rảnh rỗi.
Giá trị trả về
Một Promise.
Ngoại lệ
NotAllowedErrorDOMException-
Việc sử dụng tính năng này bị chặn bởi Permissions Policy.
Ví dụ
Ví dụ dưới đây minh họa cách bắt đầu phát hiện rảnh rỗi bằng đối số options. Nó lấy một phiên bản AbortSignal từ phiên bản AbortController.
const controller = new AbortController();
const signal = controller.signal;
await idleDetector.start({
threshold: 60_000,
signal,
});
console.log("IdleDetector is active.");
Thông số kỹ thuật
| Specification |
|---|
| Idle Detection API> # api-idledetector-start> |