1

我正在尝试为网络实现推送通知。当尝试检查天气网络应用程序是否打开时,Firefox 向服务人员抛出一个奇怪的错误。它在 chrome 上运行良好。

“Service Worker 事件 waitUntil() 传递了一个被拒绝的承诺,该承诺被 'NotSupportedError: Operation is not supported' 拒绝。”

如果我将“includeUncontrolled”设置为 false,则 firefox 和 chrome 都会返回“windowClients”一个空白数组。没有检测到页面。

这是我的推送事件处理程序,“clients.matchAll”是第 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;
        }
      })
      );
});

萤火虫截图

萤火虫截图

4

1 回答 1

2

includeUncontrolled选项已在 Firefox 45 中引入:https ://bugzilla.mozilla.org/show_bug.cgi?id=1229056 。

它尚未向后移植到 Firefox 44:https ://hg.mozilla.org/releases/mozilla-release/file/f315bde4ae0f/dom/workers/ServiceWorkerClients.cpp#l583 。

于 2016-02-11T12:57:22.053 回答