Open wanderview opened 8 years ago
Pre F2F notes: Let's make sure we have all the use cases here. Do we need clientuncontrolled? Realise that's been avoided in the past with sharedworker.
I think something like clientuncontrolled
is harder with SharedWorker since its lifecycle is tied to the GC of the attached documents. In ServiceWorker case controller state is tied to window activity. So it becomes uncontrolled when the window is closed or iframe.remove() happens.
I'm not sure about worker clients, though. Those might still be based on GC.
I'm not really convinced we understand the lifetime of a window well enough though. E.g., when you navigate the previous window can still be there in some form. Is there a clear enough action in HTML (that is implemented as such too) we can tie this too?
Service worker control is tied to "active" documents and windows AFAICT. We are pretty consistent in wpt tests in expecting frame.remove()
to no longer be controlled. In addition, we already have to deal with no longer controlling documents in the bfcache, etc.
Whether we have the right text in the spec or not, I don't know. But it is happening today.
It looks like document client-wise, 7.8.10 History Traversal's step 3 Make entry's Document object the active document of the browsing context.
can correspond to "clientcontrolled", it just needs an "other applicable specifications" algorithm callout here. This covers:
For "clientuncontrolled", it seems like unload a document is already linked in appropriately. Specifically, Handle Service Worker Client Unload's "unloading" link links to HTML's unload a document
and we can add a step in the SW spec there already. (HTML's unload a document
Step 10 explicitly says Run any unloading document cleanup steps for Document that are defined by this specification and other applicable specifications.
The only reason one might want a change is if we want the parent document to notify ahead of its iframes; those get unloaded in step 13.)
I suspect we want "fully active" documents, not just active. Still, there's a whole bunch of things around the lifecycle of documents that is not interoperable.
F2F: clientcontrolled
is more important than clientuncontrolled
. clientuncontrolled
may be unwanted, as it involves spinning something new up, when we're wanting to tear down a process.
Here are some other cases where a clientcontrolled
event would be useful. Currently we can create controlled clients without a FetchEvent in a number of ways:
Edit: Note, in Firefox 58 and earlier we did not change the client id on document.open() even though we replaced the global. We were incorrectly tying the client to the document. In Firefox 59 we start minting a new client id to reflect the new global.
I'd like to tentatively propose that we fire a
clientcontrolled
event on the ServiceWorkerGlobalScope when that worker begins controlling a client. There could also be aclientuncontrolled
event, but that is less important to me at the moment.This could enable service workers to maintain and track state more specifically than they can do today. Right now SWs can infer which clients are going to be controlled from FetchEvent, but its really an approximation. Some documents will fail to load or be closed. Exposing these events would provide better tracking.
My real reason for suggesting this, though, is to handle a corner case with bfcache. I realize firefox might be the only browser to implement bfcache, so this may not be a strong argument. But consider the following situation:
Some options we considered, but currently don't like:
I'm open to suggestions, but the
clientcontrolled
event would have wider application and would let the SW behave sensibly to this case.