w3c / w3c/ServiceWorker

consider exposing self.clients on window and other worker globals

Open
#955 9 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

apr-2017-f2f needs spec
Dominant language
Bikeshed
Stars
3.6k
Forks
324
Avg merge
14d 22h
Merged PRs (30d)
1

Description

The Clients and Client interfaces are pretty close to being a generic API for querying and manipulating windows/workers in the browser. Its nicer than things like window.open() though because its designed to be async and is less permissive in what the caller can do.

I think we should consider exposing Clients and Client interfaces on windows and other worker globals. Perhaps as navigator.clients to avoid name collisions.

To do this we would need to specialize the interface for service workers a bit, though:

  1. Clients.claim() does not make sense outside of a service worker global.
  2. Client.postMessage() currently goes to navigator.serviceWorker.onmessage. This would need to still happen for service worker globals. When used from other globals we would need to fire the event at a different target. Perhaps navigator.clients.onmessage.
  3. The behavior of clients.matchAll() only returning controlled Client objects only makes sense for service worker globals. Other globals should probably imply includeUncontrolled:true.

All same-origin restrictions would still apply. I assume we would only support this in secure contexts.

If we think we might want to do this it would be nice to do it sooner rather than later. Over time we will probably have more service worker specific features creep into the API.

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 existing Clients and Client interfaces and the service-worker-specific behavior described in the issue. Compare navigator.clients exposure, Clients.claim(), Client.postMessage(), and clients.matchAll() across window and worker globals. Done means the supported globals, event targets, control rules, and secure-context restrictions are specified.

Written by the indexing model from the issue text.

Assessment

Domain
api, web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.