ServiceWorkerGlobalScope.skipWaiting() - Web APIs 编辑
The ServiceWorkerGlobalScope.skipWaiting()
method of the ServiceWorkerGlobalScope
forces the waiting service worker to become the active service worker.
Use this method with Clients.claim()
to ensure that updates to the underlying service worker take effect immediately for both the current client and all other active clients.
Syntax
ServiceWorkerGlobalScope.skipWaiting().then(function() {
//Do something
});
Returns
A Promise
that immediately resolves with undefined
.
Example
While self.skipWaiting()
can be called at any point during the service worker's execution, it will only have an effect if there's a newly installed service worker that might otherwise remain in the waiting
state. Therefore, it's common to call self.skipWaiting()
from inside of an InstallEvent
handler.
The following example causes a newly installed service worker to progress into the activating
state, regardless of whether there is already an active service worker.
self.addEventListener('install', function(event) {
// The promise that skipWaiting() returns can be safely ignored.
self.skipWaiting();
// Perform any other actions required for your
// service worker to install, potentially inside
// of event.waitUntil();
});
Specifications
Specification | Status | Comment |
---|---|---|
Service Workers The definition of 'skipWaiting()' in that specification. | Working Draft | Initial definition. |
Browser compatibility
BCD tables only load in the browser
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论