Run subscribe only when serviceWorker.ready resolves

The register promise may resolve even when the serviceWorker is not ready,
this makes sure it is ready to setup a subscription.
This commit is contained in:
Sebastiaan Lokhorst 2018-04-08 14:29:41 +02:00
Родитель ce00ab33d6
Коммит c34769a9fa
7 изменённых файлов: 21 добавлений и 7 удалений

Просмотреть файл

@ -1,5 +1,7 @@
// Register a Service Worker.
navigator.serviceWorker.register('service-worker.js')
navigator.serviceWorker.register('service-worker.js');
navigator.serviceWorker.ready
.then(function(registration) {
// Use the PushManager to get the user's subscription to the push service.
return registration.pushManager.getSubscription()

Просмотреть файл

@ -1,5 +1,7 @@
// Register a Service Worker.
navigator.serviceWorker.register('service-worker.js')
navigator.serviceWorker.register('service-worker.js');
navigator.serviceWorker.ready
.then(function(registration) {
// Use the PushManager to get the user's subscription to the push service.
return registration.pushManager.getSubscription()

Просмотреть файл

@ -1,5 +1,7 @@
// Register a Service Worker.
navigator.serviceWorker.register('service-worker.js')
navigator.serviceWorker.register('service-worker.js');
navigator.serviceWorker.ready
.then(function(registration) {
// Use the PushManager to get the user's subscription to the push service.
return registration.pushManager.getSubscription()

Просмотреть файл

@ -1,5 +1,7 @@
// Register a Service Worker.
navigator.serviceWorker.register('service-worker.js')
navigator.serviceWorker.register('service-worker.js');
navigator.serviceWorker.ready
.then(function(registration) {
// Use the PushManager to get the user's subscription to the push service.
return registration.pushManager.getSubscription()

Просмотреть файл

@ -1,5 +1,7 @@
// Register a Service Worker.
navigator.serviceWorker.register('service-worker.js')
navigator.serviceWorker.register('service-worker.js');
navigator.serviceWorker.ready
.then(function(registration) {
// Use the PushManager to get the user's subscription to the push service.
return registration.pushManager.getSubscription()

Просмотреть файл

@ -1,5 +1,7 @@
// Register a Service Worker.
navigator.serviceWorker.register('service-worker.js')
navigator.serviceWorker.register('service-worker.js');
navigator.serviceWorker.ready
.then(function(registration) {
// Use the PushManager to get the user's subscription to the push service.
return registration.pushManager.getSubscription()

Просмотреть файл

@ -1,5 +1,7 @@
// Register a Service Worker.
navigator.serviceWorker.register('service-worker.js')
navigator.serviceWorker.register('service-worker.js');
navigator.serviceWorker.ready
.then(function(registration) {
// Use the PushManager to get the user's subscription to the push service.
return registration.pushManager.getSubscription()