Bug 226407 - ServiceWorker matchAll and FetchEvent return incorrect client info
Summary: ServiceWorker matchAll and FetchEvent return incorrect client info
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: Service Workers (show other bugs)
Version: WebKit Nightly Build
Hardware: All All
: P2 Normal
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-05-28 17:25 PDT by apple-rth
Modified: 2021-06-07 02:19 PDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description apple-rth 2021-05-28 17:25:55 PDT
The page at https://rhashimoto.github.io/serviceworker-clientid/src/
logs FetchEvent.clientId and clients.matchAll({ type: 'all' }) for requests made from both a Window and a Worker. The expectation is that the clientId should be different and matchAll({ type: 'all' }) should have entries for both the Window and Worker when both are instantiated.

Instead, WebKit only seems to know about the Window. Here is the copied text from the above URL:

5:19:35 PM (sw): Hello from Service Worker!
5:19:35 PM (sw): 46-61 /serviceworker-clientid/src/from-window
[
  {
    "frameType": "top-level",
    "id": "46-61",
    "type": "window",
    "url": "https://rhashimoto.github.io/serviceworker-clientid/src/"
  }
]
5:19:35 PM (sw): 46-61 /serviceworker-clientid/src/from-worker
[
  {
    "frameType": "top-level",
    "id": "46-61",
    "type": "window",
    "url": "https://rhashimoto.github.io/serviceworker-clientid/src/"
  }
]

Chrome has a similar problem, and I have also filed a bug there (https://bugs.chromium.org/p/chromium/issues/detail?id=1214362&q=&can=4). Firefox works correctly; here is the Firefox output:

5:21:29 PM (sw): Hello from Service Worker!
5:21:29 PM (sw): 36caec94-de12-d74a-9fde-4f18b5749b63 /favicon.ico
[
  {
    "frameType": "top-level",
    "id": "36caec94-de12-d74a-9fde-4f18b5749b63",
    "type": "window",
    "url": "https://rhashimoto.github.io/serviceworker-clientid/src/"
  }
]
5:21:29 PM (sw): 36caec94-de12-d74a-9fde-4f18b5749b63 /serviceworker-clientid/src/from-window
[
  {
    "frameType": "top-level",
    "id": "36caec94-de12-d74a-9fde-4f18b5749b63",
    "type": "window",
    "url": "https://rhashimoto.github.io/serviceworker-clientid/src/"
  }
]
5:21:29 PM (sw): 36caec94-de12-d74a-9fde-4f18b5749b63 /serviceworker-clientid/src/worker.js
[
  {
    "frameType": "top-level",
    "id": "36caec94-de12-d74a-9fde-4f18b5749b63",
    "type": "window",
    "url": "https://rhashimoto.github.io/serviceworker-clientid/src/"
  }
]
5:21:29 PM (sw): 74a1067e-1bd8-b34f-bf8b-e6de36cfa22e /serviceworker-clientid/src/from-worker
[
  {
    "frameType": "top-level",
    "id": "36caec94-de12-d74a-9fde-4f18b5749b63",
    "type": "window",
    "url": "https://rhashimoto.github.io/serviceworker-clientid/src/"
  },
  {
    "frameType": "none",
    "id": "74a1067e-1bd8-b34f-bf8b-e6de36cfa22e",
    "type": "worker",
    "url": "https://rhashimoto.github.io/serviceworker-clientid/src/worker.js"
  }
]

Note that the Firefox "from-window" request and "from-worker" request have different clientId, and after the Worker has been created matchAll({ type: 'all' }) returns information for the Worker as well as the Window.

The code for the test page can be viewed at:
https://github.com/rhashimoto/serviceworker-clientid/tree/master/src
Comment 1 apple-rth 2021-05-28 19:35:32 PDT
It looks like Bug 184294 covers part of this bug, that FetchEvent from a Worker request has the same clientId property as a Window request.

The remaining part of the bug is that matchAll({ type: 'all' }) does not contain a Worker entry.
Comment 2 Radar WebKit Bug Importer 2021-06-04 17:26:19 PDT
<rdar://problem/78893212>
Comment 3 youenn fablet 2021-06-07 02:19:48 PDT
(In reply to apple-rth from comment #1)
> It looks like Bug 184294 covers part of this bug, that FetchEvent from a
> Worker request has the same clientId property as a Window request.
> 
> The remaining part of the bug is that matchAll({ type: 'all' }) does not
> contain a Worker entry.

Right, we do not support worker clients. Currently, they are considered as part of the window client that created the workers.