WindowClient
Service Worker API の WindowClient
インターフェイスは、アクティブなワーカーによって制御される閲覧コンテキスト内のドキュメントであるサービスワーカークライアントのスコープを表します。 サービスワーカークライアントは、それ自身の読み込みとサブリソースに対してサービスワーカーを個別に選択して使用します。
メソッド
WindowClient
は、親インターフェースである Client
からメソッドを継承します。
WindowClient.focus()
-
現在のクライアントにユーザー入力フォーカスを与えます。
-
指定された URL を制御されたクライアントのページに読み込みます。
プロパティ
WindowClient
は、親インターフェースである Client
からプロパティを継承します。
WindowClient.focused
読取専用-
現在のクライアントにフォーカスがあるかどうかを示すブール値。
WindowClient.visibilityState
読取専用-
現在のクライアントの可視性を示します。 この値は、
"hidden"
、"visible"
、"prerender"
のいずれかです。
例
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) {
client.focus();
break;
}
}
if (clients.openWindow)
return clients.openWindow('/');
}));
});
仕様
Specification |
---|
Service Workers # windowclient |
ブラウザーの互換性
BCD tables only load in the browser