-
Notifications
You must be signed in to change notification settings - Fork 312
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inconsistencies due to when clients are created #870
Comments
Related Chrome bug https://bugs.chromium.org/p/chromium/issues/detail?id=514148 |
I think this is a Firefox bug and chrome is more correct. The current spec says to control windows. And it says to associate the service worker with the window (i.e. control it) before firing the FetchEvent. So there should be an existing controlled client when a navigation FetchEvent is fired. The problem in Firefox is that we control documents, not windows. The document does not exist before the navigation, so we don't have a controlling client yet. There is a bug open for this, but there was some discussion at the last f2f that we might want to change to controlling documents in the spec. So we have not moved on this. https://bugzilla.mozilla.org/show_bug.cgi?id=1237498 In regards to this spec language:
I think the spec is trying to check for a non-secure parent window. It probably needs to be re-worded since it should use the navigation URL security and parent window security to make this determination. |
We should talk about this at the f2f. I think the Firefox behaviour makes more sense, especially given what we do with |
If we decide to keep the "client is Window" behavior currently in spec, then I think we could revisit providing a value in |
This issue is very related to #811 |
F2F:
Some of the naming is up for bikeshedding, specifically:
|
|
For worker requests |
@jakearchibald Can we mark this one decided? I thought we decided it in the meeting. |
Since we didn't explicitly discuss this, I wonder if what we came up with also sufficiently addresses worker clients. For workers their settings object (client?) is created before the worker is fetched, and that worker is then used as the client for the actual request to fetch the worker. So would that be an exception to the |
I think this is not true. The fetch in run a worker is invoked with outside settings which is the source client. |
I outlined the redefinition of the service worker client concept: https://gist.github.com/jungkees/03d4473ae47bd222539ab9cf5c9afd31 Hooks to HTML's navigation and run a worker will be needed (with some changes to whatwg/html#322). In the gist proposal, I suggested we have a single .potentialClientId (with its state defined) over having both .reservedClientId and .targetClientId. Please take a look. /cc @annevk @jakearchibald @slightlyoff @mkruisselbrink @wanderview @ehsan |
I don't really understand the motivation. It says a service worker can outlive a client, and then it goes on about how a service worker exists before a client is created. How does this work in browsers today? Supposedly we always know when we are creating a new client, so we could generate an ID that we then later use once the client is created. Is that what you're trying to accomplish here? |
This is what I suggested.
In order to do that, the step 4 and 6 above should be added. And for this, I wanted to have some internal slots for id and active worker on a fetch algorithm instance or on a request.
Blink creates some corresponding state (object) when fetch occurs, and the properties in that object are later associated with the the document/worker. So, largely the steps I suggest here is what the implementation does now. |
I think it would be better if we created the ID between step 1 and 2 and pass that along in the request. After all, navigate ends up creating the document which is presumably where this information is stored eventually. |
(And a similar setup for workers.) |
This sounds fine to me. How about the matched active worker? Handle fetch should be the best place for this I think. Any better idea? |
That would mean it would have to somehow make its way back up the chain (e.g., by sticking on a response), which seems a little ugly. What is needed to determine the active worker? |
Right. Determining the active worker is done in Handle Fetch step 12.3. That is, the fetch is for a non-subresource request and the scope of the request url matches one of the registrations. |
Okay, so the worry is about some kind of race condition if we match twice on the URL? I think you have mentioned that earlier. The operations performed on client there don't make sense, right? Client doesn't exist yet for non-subresource requests. I think here too it makes more sense if we end up dictating what service worker to use. Rather than letting "Handle Fetch" figure it out somehow and tell us about it later what it came up with. It also seems plausible we might have more such cases in the future where you'd want to fetch something using a particular service worker. One way to do this would be to change the "skip-service-worker flag" of request into a "service worker" setting. Which is one of "none", "client", or a service worker instance of sorts. |
Note, we're unlikely to get any review here from google folks while google I/O is going on this week. |
@annevk I'm looking at more of how the implementations currently work. Blink finds matched registration in navigation algorithm equivalent phase and get its active worker right before dispatching the fetch event (in handle fetch algorithm equivalent phase). Your suggestion seems okay to me now. Let me try to examine a bit more next week. @wanderview Google folks will be able to have a look by then. On the spec side, Anne and I can discuss, and on the API side, more discussion would be needed I guess. |
I think we should rather set the matched service worker registration to a request rather than the active worker. The active worker can change (by waiting worker being promoted) between the step in navigation and the step later in Handle Fetch if the registration has had both the active worker and the waiting worker. Also, in the same reason, the active worker that will be attached to the client (document or other worker) should be determined when the registration's active worker for the fetch event is determined (in Handle Fetch). So, it seems to me that the active worker should be passed back to the caller within a response. Or can we create some outer object in navigate that has the active worker slot and pass the reference to fetch/Handle Fetch and change its state in the Handle Fetch? |
That seems like an unfortunate setup since in general fetch doesn't need to know about this, only for navigation. |
Before this patch, we didn't have a concept that holds reserved client's information referenced from a service worker during a navigation (more precisely before the actual global object and its relevant environment settings object for the resulting resource is created). This patch defines an "environment" concept (a supertype object of an environment settings object) that has its id, creation URL and target browsing context such that service workers' FetchEvent hanlder can reference this client information before the corresponding environmet setings object is actually created. The changes include: - Create an environment (a reserved client) during a navigation - Set request's reserved client id such that fetch (and Handle Fetch) can use it - Set request's target client id such that fetch (and Handle Fetch) can use it - Add Window object's active worker internal slot - Add WorkerGlobalObject's active worker internal slot - Add "match service worker registration" logic to attach controller Related issue: w3c/ServiceWorker#870 Call flow: w3c/ServiceWorker#870 (comment) Expected behavior: w3c/ServiceWorker#870 (comment) Related changes: - SW (WIP): w3c/ServiceWorker@df39d89 - Fetch: whatwg/fetch#383
This patch fixes the client matching flow and exposes reserved client and target client information by adding necessary hooks to fetch and HTML. Related issue: #870 Call flow: #870 (comment) Expected behavior: #870 (comment) Related changes: - HTML: whatwg/html#1776 - Fetch: whatwg/fetch#383 * Work on Handle Fetch is done. Work on the client API is in progress.
This patch fixes the client matching flow and exposes reserved client and target client information by adding necessary hooks to fetch and HTML. Related issue: #870 Call flow: #870 (comment) Expected behavior: #870 (comment) Related changes: - HTML: whatwg/html#1776 - Fetch: whatwg/fetch#383 * Work on Handle Fetch is done. Work on the client API is in progress.
This patch defines request's reserved client id and target client id that are set to a reserved environment's id and the target browsing context's active document's settings object's id respectively during a navigation. The given values are primarily used to provide the reserved client's id and target client's id to service workers' fetch event handlers. Related issue: w3c/ServiceWorker#870 Call flow: w3c/ServiceWorker#870 (comment) Expected behavior: w3c/ServiceWorker#870 (comment) Related changes: - HTML: whatwg/html#1776 - SW (WIP): w3c/ServiceWorker@df39d89
This patch fixes the client matching flow and exposes reserved client and target client information by adding necessary hooks to fetch and HTML. Related issue: #870 Call flow: #870 (comment) Expected behavior: #870 (comment) Related changes: - HTML: whatwg/html#1776 - Fetch: whatwg/fetch#383 * Work on Handle Fetch is done. Work on the client API is in progress.
This patch fixes the client matching flow and exposes reserved client and target client information by adding necessary hooks to fetch and HTML. Related issue: #870 Call flow: #870 (comment) Expected behavior: #870 (comment) Related changes: - HTML: whatwg/html#1776 - Fetch: whatwg/fetch#383 * Work on Handle Fetch is done. Work on the client API is in progress.
Before this patch, there has been no concept that holds reserved client's information referenced from a service worker during a navigation (more precisely before the actual global object and its relevant environment settings object for the resulting resource is created). This patch defines an "environment" concept (a supertype object of an environment settings object) that has an id, a creation URL, a target browsing context, and an active service worker such that service workers' FetchEvent handlers can reference this client information before the corresponding environment settings object is actually created. The changes include: - Create an environment (a reserved client) during a navigation; for worker creation requests, create an environment settings object and set the fields correspondingly - Set request's reserved client to the created environment or environment settings object such that fetch (and Handle Fetch) can use it - Set request's target client id such that fetch (and Handle Fetch) can use it Note: The reserved client's active service worker is set, if available, during the fetch (in service worker's Handle Fetch algorithm). Related issue: w3c/ServiceWorker#870 Related change: whatwg/fetch#383
This patch defines request's reserved client id and target client id that are set to a reserved environment's id and the target browsing context's active document's settings object's id respectively during a navigation. The given values are primarily used to provide the reserved client's id and target client's id to service workers' fetch event handlers. Related issue: w3c/ServiceWorker#870 Call flow: w3c/ServiceWorker#870 (comment) Expected behavior: w3c/ServiceWorker#870 (comment) Related changes: - HTML: whatwg/html#1776 - SW (WIP): w3c/ServiceWorker@df39d89
This patch defines the request's reserved client and the target client id. The reserved client of a request is set to an environment or an environment settings object during a navigation or a worker creation request, respectively. The target client id of a request is set to the target browsing context's active document's environment settings object's id during a navigation. The given values are primarily used to provide the reserved client's id and target client's id to service workers' fetch event handlers. This removes the request's target browsing context as the reserved client provides the same information. Related issue: w3c/ServiceWorker#870 Related change: whatwg/html#1776
This patch defines the request's reserved client and the target client id. The reserved client of a request is set to an environment or an environment settings object during a navigation or a worker creation request, respectively. The target client id of a request is set to the target browsing context's active document's environment settings object's id during a navigation. The given values are primarily used to provide the reserved client's id and target client's id to service workers' fetch event handlers. This removes the request's target browsing context as the reserved client provides the same information. Related issue: w3c/ServiceWorker#870 Related change: whatwg/html#1776
This patch defines the request's reserved client and the target client id. The reserved client of a request is set to an environment or an environment settings object during a navigation or a worker creation request, respectively. The target client id of a request is set to the target browsing context's active document's environment settings object's id during a navigation. The given values are primarily used to provide the reserved client's id and target client's id to service workers' fetch event handlers. This removes the request's target browsing context as the reserved client provides the same information. Related issue: w3c/ServiceWorker#870 Related change: whatwg/html#1776
Status note:
|
The issue has been addressed by adding/modifying the relevant concepts and steps in SW, HTML (navigate, run a worker, etc.), and Fetch. (See #870 (comment) for the related changes.) Closing. |
The spec calls out some cases where this can resolve to undefined, such as navigation preload not being turned on. See the cases where preloadResponse resolves to undefined in this algorithm: https://w3c.github.io/ServiceWorker/#on-fetch-request-algorithm Also add targetClientId and reservedClientId to the spec from w3c/ServiceWorker#870 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=164604919
*** Reason for rollback *** Breakages. *** Original change description *** Correct typing of the FetchEvent.preloadResponse property a little. The spec calls out some cases where this can resolve to undefined, such as navigation preload not being turned on. See the cases where preloadResponse resolves to undefined in this algorithm: https://w3c.github.io/ServiceWorker/#on-fetch-request-algorithm Also add targetClientId and reservedClientId to the spec from w3c/ServiceWorker#870 *** ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=164614311
Based on https://w3c.github.io/performance-timeline/#dom-performanceobservercallback Also add targetClientId and reservedClientId to the spec from w3c/ServiceWorker#870 ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=164927249
Before this patch, there has been no concept that holds reserved client's information referenced from a service worker during a navigation (more precisely before the actual global object and its relevant environment settings object for the resulting resource is created). This patch defines an "environment" concept (a supertype object of an environment settings object) that has an id, a creation URL, a target browsing context, and an active service worker such that service workers' FetchEvent handlers can reference this client information before the corresponding environment settings object is actually created. The changes include: - Create an environment (a reserved client) during a navigation; for worker creation requests, create an environment settings object and set the fields correspondingly - Set request's reserved client to the created environment or environment settings object such that fetch (and Handle Fetch) can use it - Set request's target client id such that fetch (and Handle Fetch) can use it Note: The reserved client's active service worker is set, if available, during the fetch (in service worker's Handle Fetch algorithm). Related issue: w3c/ServiceWorker#870 Related change: whatwg/fetch#383
The ServiceWorker assigns an app-version to a each client to ensure that all subsequent requests for a client are served using the same app-version. The assignment is done based on the client ID. Previously, the ServiceWorker would only try to read the client's ID off of the `FetchEvent`'s `clientId` property. However, on navigation requests the new client's ID will be set on [resultingClientId][1], while `clientId` will either be empty or hold the ID of the client where the request initiated from. See also related discussions in w3c/ServiceWorker#870 and w3c/ServiceWorker#1266. In theory, this could lead to the navigation request (i.e. `index.html`) being served from a different app-version than the subsequent sub-resource requests (i.e. assets). In practice, the likelihood of this happening is probably very low though, since it would require the latest app-version to be updated between the initial navigation request and the first sub-resource request, which should happen very shortly after the navigation request. This commit ensures that the correct client ID is inferred even for nabigation requests by also taking the `resultingClientId` property into account. [1]: https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent/resultingClientId
…ests The ServiceWorker assigns an app-version to a each client to ensure that all subsequent requests for a client are served using the same app-version. The assignment is done based on the client ID. Previously, the ServiceWorker would only try to read the client's ID off of the `FetchEvent`'s `clientId` property. However, for navigation requests the new client's ID will be set on [resultingClientId][1], while `clientId` will either be empty or hold the ID of the client where the request initiated from. See also related discussions in w3c/ServiceWorker#870 and w3c/ServiceWorker#1266. In theory, this could lead to the navigation request (i.e. `index.html`) being served from a different app-version than the subsequent sub-resource requests (i.e. assets). In practice, the likelihood of this happening is probably very low though, since it would require the latest app-version to be updated between the initial navigation request and the first sub-resource request, which should happen very shortly after the navigation request. This commit ensures that the correct client ID is determined even for navigation requests by also taking the `resultingClientId` property into account. [1]: https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent/resultingClientId
…ests The ServiceWorker assigns an app-version to a each client to ensure that all subsequent requests for a client are served using the same app-version. The assignment is done based on the client ID. Previously, the ServiceWorker would only try to read the client's ID off of the `FetchEvent`'s `clientId` property. However, for navigation requests the new client's ID will be set on [resultingClientId][1], while `clientId` will either be empty or hold the ID of the client where the request initiated from. See also related discussions in w3c/ServiceWorker#870 and w3c/ServiceWorker#1266. In theory, this could lead to the navigation request (i.e. `index.html`) being served from a different app-version than the subsequent sub-resource requests (i.e. assets). In practice, the likelihood of this happening is probably very low though, since it would require the latest app-version to be updated between the initial navigation request and the first sub-resource request, which should happen very shortly after the navigation request. This commit ensures that the correct client ID is determined even for navigation requests by also taking the `resultingClientId` property into account. [1]: https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent/resultingClientId
…ests The ServiceWorker assigns an app-version to a each client to ensure that all subsequent requests for a client are served using the same app-version. The assignment is done based on the client ID. Previously, the ServiceWorker would only try to read the client's ID off of the `FetchEvent`'s `clientId` property. However, for navigation requests the new client's ID will be set on [resultingClientId][1], while `clientId` will either be empty or hold the ID of the client where the request initiated from. See also related discussions in w3c/ServiceWorker#870 and w3c/ServiceWorker#1266. In theory, this could lead to the navigation request (i.e. `index.html`) being served from a different app-version than the subsequent sub-resource requests (i.e. assets). In practice, the likelihood of this happening is probably very low though, since it would require the latest app-version to be updated between the initial navigation request and the first sub-resource request, which should happen very shortly after the navigation request. This commit ensures that the correct client ID is determined even for navigation requests by also taking the `resultingClientId` property into account. [1]: https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent/resultingClientId
…ests (#42607) The ServiceWorker assigns an app-version to a each client to ensure that all subsequent requests for a client are served using the same app-version. The assignment is done based on the client ID. Previously, the ServiceWorker would only try to read the client's ID off of the `FetchEvent`'s `clientId` property. However, for navigation requests the new client's ID will be set on [resultingClientId][1], while `clientId` will either be empty or hold the ID of the client where the request initiated from. See also related discussions in w3c/ServiceWorker#870 and w3c/ServiceWorker#1266. In theory, this could lead to the navigation request (i.e. `index.html`) being served from a different app-version than the subsequent sub-resource requests (i.e. assets). In practice, the likelihood of this happening is probably very low though, since it would require the latest app-version to be updated between the initial navigation request and the first sub-resource request, which should happen very shortly after the navigation request. This commit ensures that the correct client ID is determined even for navigation requests by also taking the `resultingClientId` property into account. [1]: https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent/resultingClientId PR Close #42607
…ests (#42607) The ServiceWorker assigns an app-version to a each client to ensure that all subsequent requests for a client are served using the same app-version. The assignment is done based on the client ID. Previously, the ServiceWorker would only try to read the client's ID off of the `FetchEvent`'s `clientId` property. However, for navigation requests the new client's ID will be set on [resultingClientId][1], while `clientId` will either be empty or hold the ID of the client where the request initiated from. See also related discussions in w3c/ServiceWorker#870 and w3c/ServiceWorker#1266. In theory, this could lead to the navigation request (i.e. `index.html`) being served from a different app-version than the subsequent sub-resource requests (i.e. assets). In practice, the likelihood of this happening is probably very low though, since it would require the latest app-version to be updated between the initial navigation request and the first sub-resource request, which should happen very shortly after the navigation request. This commit ensures that the correct client ID is determined even for navigation requests by also taking the `resultingClientId` property into account. [1]: https://developer.mozilla.org/en-US/docs/Web/API/FetchEvent/resultingClientId PR Close #42607
https://jakearchibald.github.io/isserviceworkerready/demos/clients-count/
Chrome says 1, Firefox says 0.
The Firefox behaviour seems right to me, but unless I'm reading it wrong, the spec isn't clear around this. This might be because of earlier confusion around when clients are created.
From https://html.spec.whatwg.org/multipage/browsers.html#navigating-across-documents:
If I'm reading this correctly, the client is the window being navigated, not a new client ready for the new page.
From https://slightlyoff.github.io/ServiceWorker/spec/service_worker/#on-fetch-request-algorithm 12.1:
This seems to assume that the client is a new client ready for the new page, but doesn't this mean that SW will fail if you're navigating from an unrelated insecure page?
The text was updated successfully, but these errors were encountered: