-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Introduce a browsing context group #4198
Comments
I believe that membership into a Browsing Context Group shouldn't be too complex (although there are certainly edge cases):
One reason why I haven't tried to do this before is the noopener case, and how there may be some ugly edge cases around maintaining some concept of connectedness (for the purposes of e.g. popup blocking), while not causing noopener documents to join the same Browsing Context Group. In terms of Unit of Related Similar-Origin Browsing Contexts, I'm imagining it can be defined as "Globals in a Window Agent", where two same-site documents must share an event loop (and thus a Window Agent), if they are in the same Browsing Context Group. |
I hope we can reuse the same terms and fix their definitions, instead of creating two parallel ones. Separately, can you spell out why they need to remain in the same agent cluster? I can see how that's the case if they're already sharing memory, but if they haven't done so yet, then it seems like a valid and unobservable thing to do to move them to separate processes and prohibit further sharing. |
I think the goal here is to kill the old terms entirely, not create two parallel terms. The old names weren't exactly amazing, so switching to a more descriptive name seems like a generally good thing. I also don't want to have two parallel similar-but-not-identical definitions in the spec.
I ideally don't want the spec to require that browser authors keep track of which globals have references to which WindowProxy objects in order to make decisions about Browsing Context Group or Window Agent membership. Window Agent membership is currently observable using BroadcastChannel (e.g. #3759), so it would be good to have a well defined mechanism for defining what it implies in the spec. To my knowledge no browser can move an executing live JS environment between processes, and doing so would probably be prohibitively expensive. If that is at some point possible, then it would theoretically be possible for Window Agent membership is specific to a single global, so during navigations, it is certainly possible to switch processes. The concern would be that if we say have:
I'm guessing you want to be able to have loaded My worry around that is potentially requiring tracking the WindowProxy references created to every related window for each global in order to be spec compliant (e.g. WRT |
Thanks for explaining. The WindowProxy reference issue probably indeed makes it not worth allowing the extra flexibility. Back to the naming issue, I don't think it's worthwhile creating all that spec and ecosystem churn just to bugfix a definition. If we did that every time we fixed a bug in something's definition, nobody would be able to keep track of anything in the HTML spec. Keep in mind that these terms are used in more places than just the HTML spec, so we'd need to update all those as well. |
I'm glad we agree on maximizing the opportunities for parallelization. And yeah, unless As for the data structure, I was thinking a browsing context group would hold a set of top-level/auxiliary browsing contexts (with at most one top-level), and not all descendants of those as well (as unit does). It's not clear to me the latter is a useful data structure. The other thing is that the existing uses of the term "unit of related similar-origin browsing contexts" need to say agent instead, so keeping that term around, but making it mean something entirely different, seems bad to me. It seems much better to start fresh, to make this mistake clear. |
To elaborate, I think what we want is a set of browsing context trees. A set of browsing contexts with no hierarchy isn't particularly useful, as far as I can tell. And the main terminology used outside the HTML standard is the "similar-origin" one, where "similar-origin window agent" is really what is meant. I've been meaning to update DOM to use that instead, I guess I can start there. |
Using "unit of related similar-origin browsing contexts" never made much sense as a browsing context could always hold several cross-site documents. Helps with whatwg/html#4198. Fixes #88.
So far we have many places in the spec where UORSOBCs is useful, and I haven't seen any where either of your two new concepts would be helpful. Could you elaborate? In general I would prefer not to introduce new concepts if we can avoid them.
Why? (Assuming the appropriate bugfix.)
Can you explain why this bugfix makes the term "mean something entirely different", in your estimation?
I think you underestimate the cost of starting fresh here, and overestimate how big of a mistake this is. Before shared memory, it was unobservable; we just forgot to patch the definition a bit when we introduced shared memory.
Why is that the case? |
A browsing context holds a sequence of documents. It therefore logically spans agent clusters and event loops. Therefore having a concept such as "similar-origin" doesn't make sense for a browsing context, since it can have multiple origins at the same time. |
A browsing context has a distinguished active document. |
Sure, but it's not only active documents that matter. And this makes it something that changes over time, rather than something you can allocate. |
The "unit of related similar-origin browsing contexts" concept is inaccurate. Helps with #4198.
Only active documents matter in the definition of URSOBCs. I think it's much nicer to have a definition that's always right, than one that you have to manually add and remove things from. I don't think moving toward a world of manually maintaining the contents of a collection is an improvement to the spec; I think it would be a regression. |
I don't think that's true, since inactive documents also belong to the event loop, which is why this was always wrong and not at all how things are implemented. |
And also, if we want to generalize language used for shared and service workers, having a totally alien concept to manage the same thing for documents is rather weird. I'm a little surprised anyone would defend this setup. |
Hmm, you may be right about that. Could you write up an example where we have an "orphan" inactive document that doesn't get an event loop per the current definition? I tried for a bit but wasn't able to create one.
Similarly, I'm surprised anyone would seek to change it so drastically. |
I want to change it because the current setup isn't at all ready for the kind of cross-process design we need. I mean, if you simply remove a same-/cross-origin |
I believe it has a bug, as this OP points out. I think we can fix that bug and then it will work great with the cross-process design we need.
I'll try to make your example more concrete. We have 1 top-level BC with one iframe child BC. Both before and after the removal, they have a single active document, per https://html.spec.whatwg.org/#active-document. You have two scenarios, one same origin and one cross-origin. Per https://html.spec.whatwg.org/#groupings-of-browsing-contexts they are directly reachable browsing contexts and are as such in the same unit of related browsing contexts. In the same-origin case, they can be same-origin-domain with each other, and so are in the same URSOBC. In the cross-origin case, assuming different eTLD+1s they can't, and so are in different URSOBCs. In the cross-origin case with the same eTLD+1s they can, and so are in the same URSOBC. Does this help? Maybe we should add examples to the spec for cases like this? |
How are they in the same URSOBC if the |
Why wouldn't they? For example, you can still share memory with JS that runs in that page; you can still synchronously access properties of that global... The definitions bear it out, and they match implementations. |
Because the browsing context in the |
Dang, you're right! Thanks for walking me through it! Given an example like this, the only way to salvage a "simple" definition (in the sense of whatwg/dom#717 (comment)) would be to make it temporal anyway. E.g. change the bullet from "all the browsing context's child browsing contexts" to "all the browsing contexts that at some point were child browsing contexts of browsing context". But that's just a kind of awkward way of doing the explicit addition/removal you are advocating for. (Albeit a bit less error-prone, as it avoids issues where you can add but forget to remove, or similar.) So, thank you, I'm cautiously on-board with changing to explicit management of realms. Apart from that though, I hope you can work on an overview of the new paradigm you're shooting for, before we accept any piecemeal changes like #4204. In particular I'd like to ensure we don't create new concepts that are only slight variations on old ones (e.g. browsing context group/set of browsing context trees), and I'd like to preserve existing concepts as much as possible, just with different layering so they're not broken. |
I'd prefer a complete different set of names here because the current setup is way too confusing, and there are many subtle details that are going to change so that it's obvious when other specifications and implementation comments that refer to the old concepts. Subtle semantic change in this area is going to be really painful to follow up on. |
After some IRC discussion I created this overview for the "new paradigm". I hope that we can work towards this in mostly incremental steps, as doing it all at once seems rather prohibitive, though also never in a way that leaves things in a broken state (even though things are in a broken state), as per our standard practice. Main changes to the current modelA user agent:
(The maps for workers can be defined in parallel, later, or perhaps even abstractly. I don't think we need to worry about those too much for now as the existing agent cluster definition isn't too broken for them.) A browsing context group:
Notes
|
Event loops ought to be 1:1 with agents, let's make it so. Helps with #4198.
Event loops ought to be 1:1 with agents, let's make it so. Helps with #4198.
The "unit of related similar-origin browsing contexts" concept is inaccurate. Helps with #4198.
The "unit of related similar-origin browsing contexts" concept is inaccurate. Helps with #4198.
The "unit of related similar-origin browsing contexts" concept is inaccurate. Helps with #4198.
Using "unit of related similar-origin browsing contexts" never made much sense as a browsing context could always hold several cross-site documents. This also changes the structures these agents hold from lists to (ordered) sets as that's more accurate and precise. Helps with whatwg/html#4198. Fixes #88.
Some initial work to make introducing browsing context groups (see #4198) easier. Fixes #2636 by making opener browsing context more generally applicable and making window.open() set it. Fixes #2645 by removing creator browsing context and explicitly passing in the creator document. Tests: web-platform-tests/wpt#15078.
Event loops ought to be 1:1 with agents, let's make it so. Helps with #4198.
The concept of a browsing context event loop does not make much sense in a world where cross-site navigations are increasingly getting more isolated from each other. Helps with #4198.
The grouping concepts unit of related browsing contexts and unit of similar-origin browsing contexts were not accurate, due to browsing contexts being able to hold a sequence of (potentially cross-site) documents. Fixes #4198.
The "unit of related similar-origin browsing contexts" concept is inaccurate. Helps with whatwg#4198.
Some initial work to make introducing browsing context groups (see whatwg#4198) easier. Fixes whatwg#2636 by making opener browsing context more generally applicable and making window.open() set it. Fixes whatwg#2645 by removing creator browsing context and explicitly passing in the creator document. Tests: web-platform-tests/wpt#15078.
The concept of a browsing context event loop does not make much sense in a world where cross-site navigations are increasingly getting more isolated from each other. Helps with whatwg#4198.
The "unit of related similar-origin browsing contexts" concept is inaccurate. Helps with whatwg#4198.
Some initial work to make introducing browsing context groups (see whatwg#4198) easier. Fixes whatwg#2636 by making opener browsing context more generally applicable and making window.open() set it. Fixes whatwg#2645 by removing creator browsing context and explicitly passing in the creator document. Tests: web-platform-tests/wpt#15078.
The concept of a browsing context event loop does not make much sense in a world where cross-site navigations are increasingly getting more isolated from each other. Helps with whatwg#4198.
The grouping concepts unit of related browsing contexts and unit of similar-origin browsing contexts were not accurate, due to browsing contexts being able to hold a sequence of (potentially cross-site) documents. Fixes #4198.
The grouping concepts unit of related browsing contexts and unit of similar-origin browsing contexts were not accurate, due to browsing contexts being able to hold a sequence of (potentially cross-site) documents. Fixes #4198.
In "the rules for choosing a navigable," the method to find an existing navigable by name is vague. This updates the definition to accurately reflect what the major implementations do. There are some differences between implementations, so there remains in the spec some optional/implementation-defined behavior, but it's much narrower. In particular, note that lookups are now explicitly scoped to browsing context groups. The previous language in the named lookup about "the user agent determines that the two browsing contexts are related enough" is now no longer a part of the lookup logic, but a consequence of the BCG swap decisions. In "obtain a browsing context to use for a navigation response," the existing spec only mentions COOP enforcement as a reason to do a browsing context group swap. Some implementations perform a swap for additional security and performance reasons. This is now reflected in the spec. For context, see: * #313 * #4198 (comment) * #5350 This closes #313, but we have opened the following issues to track the remaining implementation-defined interop gaps: #6356, #10842, #10848, #10849, #10850. Co-authored-by: Domenic Denicola <[email protected]>
As far as I can tell the "unit of related browsing contexts" idea is broken. E.g., if a top-level opens two auxiliary browsing contexts, and all contain same-origin documents, and then the top-level closes itself or gets closed, the two auxiliary browsing contexts might not have a reference to each other's
WindowProxy
, but definitely need to remain tied as their documents need to be in the same agent cluster. However, per the current definition they'd suddenly no longer be in the same unit.Therefore, I think we need a browsing context group, which holds a set of top-level/auxiliary browsing contexts and also a map of site to agent clusters.
cc @mystor
(Note: "units of related similar-origin browsing contexts" is also broken, as a browsing context can hold many origins.)
The text was updated successfully, but these errors were encountered: