aboutsummaryrefslogtreecommitdiff
path: root/files/ko/web/api/clients/index.html
diff options
context:
space:
mode:
Diffstat (limited to 'files/ko/web/api/clients/index.html')
-rw-r--r--files/ko/web/api/clients/index.html102
1 files changed, 102 insertions, 0 deletions
diff --git a/files/ko/web/api/clients/index.html b/files/ko/web/api/clients/index.html
new file mode 100644
index 0000000000..d4365b320e
--- /dev/null
+++ b/files/ko/web/api/clients/index.html
@@ -0,0 +1,102 @@
+---
+title: Clients
+slug: Web/API/Clients
+tags:
+ - API
+ - Clients
+ - Experimental
+ - Interface
+ - NeedsTranslation
+ - Reference
+ - Service Workers
+ - Service worker API
+ - ServiceWorker
+ - TopicStub
+ - Workers
+translation_of: Web/API/Clients
+---
+<p>{{SeeCompatTable}}{{APIRef("Service Workers API")}}</p>
+
+<p><span class="seoSummary">The <code>Clients</code> interface provides access to {{domxref("Client")}} objects. Access it via <code>{{domxref("ServiceWorkerGlobalScope", "self")}}.clients</code> within a <a href="/en-US/docs/Web/API/ServiceWorker_API">service worker</a>.</span></p>
+
+<h2 id="Methods">Methods</h2>
+
+<dl>
+ <dt>{{domxref("Clients.get()")}}</dt>
+ <dd>Returns a {{jsxref("Promise")}} for a {{domxref("Client")}} matching a given {{domxref("Client.id", "id")}}.</dd>
+ <dt>{{domxref("Clients.matchAll()")}}</dt>
+ <dd>Returns a {{jsxref("Promise")}} for an array of {{domxref("Client")}} objects. An options argument allows you to control the types of clients returned. </dd>
+ <dt>{{domxref("Clients.openWindow()")}}</dt>
+ <dd>Opens a new browser window for a given url and returns a {{jsxref("Promise")}} for the new {{domxref("WindowClient")}}.</dd>
+ <dt>{{domxref("Clients.claim()")}}</dt>
+ <dd>Allows an active service worker to set itself as the {{domxref("ServiceWorkerContainer.controller", "controller")}} for all clients within its {{domxref("ServiceWorkerRegistration.scope", "scope")}}. </dd>
+</dl>
+
+<h2 id="Examples">Examples</h2>
+
+<p>The following example shows an existing chat window or creates a new one when the user clicks a notification.</p>
+
+<pre class="brush: js">addEventListener('notificationclick', event =&gt; {
+  event.waitUntil(async function() {
+    const allClients = await clients.matchAll({
+      includeUncontrolled: true
+    });
+
+    let chatClient;
+
+    // Let's see if we already have a chat window open:
+    for (const client of allClients) {
+      const url = new URL(client.url);
+
+      if (url.pathname == '/chat/') {
+        // Excellent, let's use it!
+        client.focus();
+        chatClient = client;
+        break;
+      }
+    }
+
+    // If we didn't find an existing chat window,
+ // open a new one:
+    if (!chatClient) {
+      chatClient = await clients.openWindow('/chat/');
+    }
+
+    // Message the client:
+    chatClient.postMessage("New chat messages!");
+  }());
+});
+</pre>
+
+<h2 id="Specifications">Specifications</h2>
+
+<table class="standard-table">
+ <tbody>
+ <tr>
+ <th scope="col">Specification</th>
+ <th scope="col">Status</th>
+ <th scope="col">Comment</th>
+ </tr>
+ <tr>
+ <td>{{SpecName('Service Workers', '#clients', 'Clients')}}</td>
+ <td>{{Spec2('Service Workers')}}</td>
+ <td>Initial definition</td>
+ </tr>
+ </tbody>
+</table>
+
+<h2 id="Browser_compatibility">Browser compatibility</h2>
+
+<div>
+
+
+<p>{{Compat("api.Clients")}}</p>
+</div>
+
+<h2 id="See_also">See also</h2>
+
+<ul>
+ <li><a href="/en-US/docs/Web/API/ServiceWorker_API/Using_Service_Workers">Using Service Workers</a></li>
+ <li><a href="https://jakearchibald.github.io/isserviceworkerready/">Is ServiceWorker ready?</a></li>
+ <li>{{jsxref("Promise")}}</li>
+</ul>