Provide a way to attach data to clients
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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