-
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
Proposal: Tab Knowledge API -- gaining knowledge about same-origin tabs #10193
Comments
A shared worker grants full knowledge, no? Any of the tabs can share everything they know with others in their origin group. This is just making that communication more ergonomic. (Plus tab-switching, of course.) |
It has full knowledge of when new contents are opened. But there was some question if a page can reliably know whether the tab was closed. @tdresser had some exploration on the topic. Regardless of the answer though, it may be possibly to have this full knowledge, yeah |
Assuming we ship the MessagePort onclosed event, then a shared worker grants full knowledge, except for knowing tab order and tab group ID (currently excluded from the explainer, but I think these could be safely added). |
I don't think we necessarily need the closed event. We can already achieve this with Web Locks today: https://basic-tab-knowledge-with-locks.glitch.me/ However there are a couple of points that differ from the proposed API in the explainer:
Also, I wonder if there could be a mean to distinguish which entry we are (doing the id on url or title is not enough). |
Nice solution! I think we'd want to only include top level browsing contexts. Clarifying which entry we are makes sense to me. I don't think we're aware of any use-cases which require communication between entries. |
I agree with @tdresser that I didn't think an opt-in would be necessary here. However, I think there's something to be said for incognito modes or different profiles or something like that, where it's unclear whether we should be providing the information to the page across those user defined boundaries. I'm not sure what the right spec term for this is though. |
BroadcastChannel was designed for this use case. Why is that not enough? |
pagehide is frequently never fired (e.g., tab crash, or fast tab shutdown). This proposal also enables a page to focus an existing tab, and provides a surface for (in the future) exposing tab order, or tab group ID. |
No "concrete" use-case, but that sounds like a natural extension to this feature. I guess that could be useful if you want to sync states between tabs. Of course this could also be achieved through a BroadcastChannel, but that looks more cluttered to have to set that up.
BroadcastChannel isn't really good at telling which pages are active though. While the pagehide issue could also be solved by the use of Web Locks, it's also very difficult to set up initially: you need to do a first round asking if you're alone, and you need to hope you'll get an answer in a timely manner to set up the counts otherwise you may have conflicting reports. |
Is the proposed API different from the existing Clients API (and should it be)? I know that API is currently limited to just service workers, but I don't think there were any real concerns around exposing it more widely (w3c/ServiceWorker#955), it mostly just stalled because there wasn't enough interest from browsers and site developers to spent the resources on. And if there is other functionality missing from that API it might make more sense to extend the API rather than invent an entirely new API? |
TIL about Clients API. That's almost exactly what this proposal aims to accomplish! We should possibly revive the effort to expose this outside of service workers, since that would make adoption easier. It wasn't clear to me what you mean by
Specifically, you mean the site developers would not want this exposed outside of service workers because it would somehow become burdensome to use? Or something else? One additional feature of the proposed API is the ability to switch tabs when focused. I see the WindowClient interface has focus() as well, but that doesn't seem to include the ability to actually switch a tab -- at least not that I see. Would it make sense to propose adding such functionality to the Clients API? Also, there may be future enhancement like exposing more information about the client, but that certainly can go into the Client interface as well. |
No, I meant more that work on this wasn't prioritized at the time because site developers weren't asking for it (but that might also be because they weren't aware of it). |
What problem are you trying to solve?
Hoping to improve the ergonomics of web sites accessing information about tabs opened to the same origin. Additionally allowing some minimal control (focus specifically) to be able to switch to those tabs. See https://github.com/vmpstr/web-proposals/blob/main/explainers/tab-knowledge.md
What solutions exist today?
I believe partial knowledge is available by using shared workers. These workers can track the new tabs creation and deletion and update internal tracking.
How would you solve it?
A new API that can directly provide new information. More information in the explainer
Anything else?
I'm looking for early feedback to see if this is a direction that implementors are interested in exploring.
The text was updated successfully, but these errors were encountered: