w3c / w3c/ServiceWorker

Provide a way to attach data to clients

Open
#1,475 5 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Bikeshed
Stars
3.6k
Forks
324
Avg merge
14d 22h
Merged PRs (30d)
1

Description

Originally raised while discussing whether we should have client.isFrozen etc.

There's a lot of state data we could attach to clients, but developers also postMessage clients to 'ask' for some app-specific data, like "is the user currently typing a message?".

We could improve both situations by allowing developers to attach clonable data to a client.

Rough design that I haven't put much thought into:

// From a page (or other client):
await clients.setClientData({ foo: 'bar' });
// In a service worker:
const client = (await clients.matchAll())[0];
console.log(client.data?.foo); // 'bar' or undefined.

Only the client itself will be able to set client data.

My rough API proposal includes adding self.clients to windows/workers. We might be able to avoid adding the whole clients API if we want to take baby steps here.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the proposed clients.setClientData() and client.data examples, along with the question of exposing self.clients to windows and workers. Clarify the API shape, cloning and ownership rules, and the required service-worker behavior with the maintainers. Done means the design is agreed well enough to specify and implement.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
api, web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.