mdn / content

The content behind MDN Web Docs
https://developer.mozilla.org
Other
9.11k stars 22.46k forks source link

Fetch Event client id is null #20657

Closed transformsen closed 4 days ago

transformsen commented 1 year ago

MDN URL

https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent/clientId

What specific section or headline is this issue about?

Client id is null

What information was incorrect, unhelpful, or incomplete?

As per specifications and implementation client for non subresource request is null

What did you expect to see?

Mention it is null for non subresource request

Do you have any supporting links, references, or citations?

No response

Do you have anything more you want to share?

No response

MDN metadata

Page report details * Folder: `en-us/web/api/fetchevent/clientid` * MDN URL: https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent/clientId * GitHub URL: https://github.com/mdn/content/blob/main/files/en-us/web/api/fetchevent/clientid/index.md * Last commit: https://github.com/mdn/content/commit/1511e914c6b1ce6f88056bfefd48a6aa585cebce * Document last modified: 2022-09-09T05:10:34.000Z
tlylt commented 1 year ago

Hi @transformsen, do you have the links to the specification/implementation that you mentioned?

Sorry if it's a stupid question, but does "non subresource request" here refer to requests from the origin? I can only find references about "subresource" in the context of "Subresource Integrity".

transformsen commented 1 year ago

Thanks for your reply.. Example of non subresource request is from submit. Form submit to new jsp Or servlet page Or any new webpage.

Form non subresource specification recommend to provide replacesClientid. Doc - https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent/replacesClientId Spec - https://w3c.github.io/ServiceWorker/#fetch-event-replacesClientId

But no browser have implemented it. ReplacesClientid would really help for our requirements.

Josh-Cena commented 2 months ago

I did not find information in the spec that it can be null. I'm not sure if clientId can even be the empty string. The IDL in the spec says:

interface FetchEvent : ExtendableEvent {
  constructor(DOMString type, FetchEventInit eventInitDict);
  [SameObject] readonly attribute Request request;
  readonly attribute Promise<any> preloadResponse;
  readonly attribute DOMString clientId;
  readonly attribute DOMString resultingClientId;
  readonly attribute DOMString replacesClientId;
  readonly attribute Promise<undefined> handled;

  undefined respondWith(Promise<Response> r);
};

And here are the relevant steps in initializing the event:

  1. Initialize e’s clientId attribute to client’s id.
  2. If request is a non-subresource request and request’s destination is not "report", initialize e’s resultingClientId attribute to reservedClient’s id, and to the empty string otherwise.
  3. If request is a navigation request, initialize e’s replacesClientId attribute to request’s replaces client id, and to the empty string otherwise.