Skip to content

Commit

Permalink
Adds explanation for clients global
Browse files Browse the repository at this point in the history
  • Loading branch information
himanshugarg committed Nov 17, 2023
1 parent d451eec commit f280a10
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions files/en-us/web/api/client/postmessage/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ None ({{jsxref("undefined")}}).

## Examples

Sending a message from a service worker to a client:
The code below sends a message from a service worker to a client. The client is fetched using the [get() method](/en-US/docs/Web/API/Clients/get) on [clients](/en-US/docs/Web/API/ServiceWorkerGlobalScope/clients) which is a global in service worker scope.

```js
addEventListener("fetch", (event) => {
Expand All @@ -47,7 +47,7 @@ addEventListener("fetch", (event) => {
// Eg, if it's cross-origin.
if (!event.clientId) return;

// Get the client.
// Get the client using clients, a global in worker scope
const client = await clients.get(event.clientId);
// Exit early if we don't get the client.
// Eg, if it closed.
Expand Down

0 comments on commit f280a10

Please sign in to comment.