IdleDeadline

IdleDeadline interface is used as the data type of the input parameter to idle callbacks established by calling Window.requestIdleCallback() . It offers a method, timeRemaining() , which lets you determine how much longer the user agent estimates it will remain idle and a property, didTimeout , which lets you determine if your callback is executing because its timeout duration expired.

To learn more about how request callbacks work, see Collaborative Scheduling of Background Tasks .

特性

IdleDeadline.didTimeout 只读
A Boolean whose value is true if the callback is being executed because the timeout specified when the idle callback was installed has expired.

方法

IdleDeadline.timeRemaining()
返回 DOMHighResTimeStamp , which is a floating-point value providing an estimate of the number of milliseconds remaining in the current idle period. If the idle period is over, the value is 0. Your callback can call this repeatedly to see if there's enough time left to do more work before returning.

范例

See our complete example in the article Cooperative Scheduling of Background Tasks API .

规范

规范 状态 Comment
Cooperative Scheduling of Background Tasks Proposed Recommendation

浏览器兼容性

更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
IdleDeadline Chrome 47 Edge 79 Firefox 55
55
53
Disabled
Disabled From version 53: this feature is behind the dom.requestIdleCallback.enabled preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
IE 不支持 No Opera 34 Safari 不支持 No WebView Android 47 Chrome Android 47 Firefox Android 55
55
53
Disabled
Disabled From version 53: this feature is behind the dom.requestIdleCallback.enabled preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
Opera Android 34 Safari iOS 不支持 No Samsung Internet Android 5.0
didTimeout Chrome 47 Edge 79 Firefox 55
55
53
Disabled
Disabled From version 53: this feature is behind the dom.requestIdleCallback.enabled preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
IE 不支持 No Opera 34 Safari 不支持 No WebView Android 47 Chrome Android 47 Firefox Android 55
55
53
Disabled
Disabled From version 53: this feature is behind the dom.requestIdleCallback.enabled preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
Opera Android 34 Safari iOS 不支持 No Samsung Internet Android 5.0
timeRemaining Chrome 47 Edge 79 Firefox 55
55
53
Disabled
Disabled From version 53: this feature is behind the dom.requestIdleCallback.enabled preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
IE 不支持 No Opera 34 Safari 不支持 No WebView Android 47 Chrome Android 47 Firefox Android 55
55
53
Disabled
Disabled From version 53: this feature is behind the dom.requestIdleCallback.enabled preference (needs to be set to true ). To change preferences in Firefox, visit about:config.
Opera Android 34 Safari iOS 不支持 No Samsung Internet Android 5.0

图例

完整支持
完整支持
不支持
不支持
用户必须明确启用此特征。
用户必须明确启用此特征。

另请参阅