--- title: WindowClient slug: Web/API/WindowClient tags: - API - Client - Interface - Reference - Service Workers - ServiceWorker - WindowClient translation_of: Web/API/WindowClient ---
{{APIRef("Service Workers API")}}
Service Worker API の WindowClient インターフェイスは、アクティブなワーカーによって制御される閲覧コンテキスト内のドキュメントであるサービスワーカークライアントのスコープを表します。 サービスワーカークライアントは、それ自身の読み込みとサブリソースに対してサービスワーカーを個別に選択して使用します。
WindowClient は、親インターフェースである {{domxref("Client")}} からメソッドを継承します。
WindowClient は、親インターフェースである {{domxref("Client")}} からプロパティを継承します。
"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('/');
}));
});
| 仕様 | 状態 | コメント |
|---|---|---|
| {{SpecName('Service Workers', '#windowclient', 'WindowClient')}} | {{Spec2('Service Workers')}} | 初期定義 |
{{Compat("api.WindowClient")}}