WindowClient.focused

WindowClient インターフェイスの focused 読み取り専用プロパティは、現在のクライアントにフォーカスがあるかどうかを示す Boolean です。

構文

var myFocused = windowClient.focused;

self.addEventListener('notificationclick', function(event) {
  console.log('On notification click: ', event.notification.tag);
  event.notification.close();

  // これは、クライアントが既に開いているかどうかを確認し、
  // 開いている場合にフォーカスを合わせます
  event.waitUntil(clients.matchAll({
    type: "window"
  }).then(function(clientList) {
    for (var i = 0; i < clientList.length; i++) {
      var client = clientList[i];
      if (client.url == '/' && 'focus' in client) {
        if(!client.focused)
          return client.focus();
        }
      }
    }
    if (clients.openWindow)
      return clients.openWindow('/');
  }));
});

仕様

Specification
Service Workers
# client-focused

ブラウザーの互換性

BCD tables only load in the browser