ServiceWorkerGlobalScope.skipWaiting()
方法在
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.
ServiceWorkerGlobalScope.skipWaiting().then(function() {
//Do something
});
A
Promise
that immediately resolves with
undefined
.
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();
});
| 规范 | 状态 | 注释 |
|---|---|---|
|
服务工作者
The definition of 'skipWaiting()' in that specification. |
工作草案 | 初始定义。 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
skipWaiting
|
Chrome 40 | Edge ≤79 |
Firefox
44
注意事项
|
IE 不支持 No | Opera 24 | Safari 不支持 No | WebView Android 40 | Chrome Android 40 | Firefox Android 44 | Opera Android 24 | Safari iOS 不支持 No | Samsung Internet Android 4.0 |
完整支持
不支持
实验。期望将来行为有所改变。
见实现注意事项。
ServiceWorkerGlobalScope
skipWaiting()