Skip to content

Commit

Permalink
Adds explanation in example for the use of clients global (mdn#30329)
Browse files Browse the repository at this point in the history
* Adds explanation for clients global

* Update files/en-us/web/api/client/postmessage/index.md

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>

* Update files/en-us/web/api/client/postmessage/index.md

Co-authored-by: skyclouds2001 <[email protected]>

* Update files/en-us/web/api/client/postmessage/index.md

Co-authored-by: wbamberg <[email protected]>

* Update files/en-us/web/api/client/postmessage/index.md

Co-authored-by: skyclouds2001 <[email protected]>

---------

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: skyclouds2001 <[email protected]>
Co-authored-by: wbamberg <[email protected]>
  • Loading branch information
4 people authored Nov 18, 2023
1 parent 30e5096 commit 46ee376
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 {{domxref("Clients.get()", "get()")}} method on {{domxref("ServiceWorkerGlobalScope.clients", "clients")}}, which is a global in service worker scope.

```js
addEventListener("fetch", (event) => {
Expand All @@ -48,7 +48,7 @@ addEventListener("fetch", (event) => {
if (!event.clientId) return;

// Get the client.
const client = await clients.get(event.clientId);
const client = await self.clients.get(event.clientId);
// Exit early if we don't get the client.
// Eg, if it closed.
if (!client) return;
Expand Down

0 comments on commit 46ee376

Please sign in to comment.