Dino Babu
Dino Babu

Reputation: 5809

Service Worker Window Clients Issue on Firefox - Web Push Notification

I'm trying implement push notification for web. When trying to check weather web app is open, firefox throwing a strange error on service worker. And it works fine on chrome.

"Service worker event waitUntil() was passed a promise that rejected with 'NotSupportedError: Operation is not supported'."

if i set 'includeUncontrolled' to false, both firefox and chrome returns 'windowClients' a blank array. Not detecting the page.

Here is my push event handler, 'clients.matchAll' is line 50.

// Push Notification Event Handler
self.addEventListener('push', function(event) {

  // Push Received
  event.waitUntil(

      // Check app page open
      self.clients.matchAll({ // Line 50
        includeUncontrolled: true, // Error occuring when enabling this
        type: 'window'
      })
      .then(function(windowClients) {

        // If no page instances show notification
        if (!windowClients.length) {

          // Get subscription key to call api
          return self.registration
              .pushManager
              .getSubscription()
              .then(function(subscription) {
                if (subscription) {

                  // Get push message data
                  var token = encodeURIComponent(String(subscription.endpoint).split('/').pop());
                  var url = 'api/push/data?token=' + token + '&type=' + getPushDeviceType();
                  return self.fetch(url, {credentials: 'include'})
                      .then(function(response) {

                        if (response.status === 200) {
                          return response.json()
                              .then(function(data) {
                                if (data) {

                                  // Display notification
                                  return self.registration
                                      .showNotification('App Notifications', {
                                        'body': data.msg,
                                        'icon': data.img,
                                        'tag': 'app'
                                      });
                                } else {
                                  return;
                                }
                              });
                        } else {
                          return;
                        }
                      });
                } else {
                  return;
                }
              });
        } else {
          return;
        }
      })
      );
});

Firebug Screenshot

Firebug Screenshot

Upvotes: 1

Views: 775

Answers (1)

Marco Castelluccio
Marco Castelluccio

Reputation: 10782

The includeUncontrolled option has been introduced in Firefox 45: https://bugzilla.mozilla.org/show_bug.cgi?id=1229056.

It hasn't been backported to Firefox 44: https://hg.mozilla.org/releases/mozilla-release/file/f315bde4ae0f/dom/workers/ServiceWorkerClients.cpp#l583.

Upvotes: 2

Related Questions