Skip to content

<iframe> and the History API #184

Open

Description

Activity

  1. annevk commented on Feb 16, 2016

    @annevk
    Collaborator

    @rniwa what is Apple doing here?

  2. changed the title [-][Shadow]: Figure out how session history should work for <iframe>s in shadow DOM (bugzilla: 27325)[/-] [+]<iframe> and the History API[/+] on Feb 16, 2016
  3. annevk commented on Feb 16, 2016

    @annevk
    Collaborator

    @smaug---- so I guess the problem is all the state exposed on History? If we did not expose that, would we have to expose it somehow on ShadowRoot? That each gets its own history? Presumably defaulting to no history at all for v1?

    That kind of approach makes sense if you don't want to influence your container, but if you're a simple layout component that breaks expectations. Not sure if there's a good answer here. (We could make it depend on open vs closed...)

  4. smaug---- commented on Feb 16, 2016

    @smaug----

    For open case I could possibly live with normal nested browsing context handling.
    And for closed...no session history at all? I think that is the easiest for now. history.pushState/replaceState would do what? and what about history.go(x)? Throw?
    I think throw is the only sane option, except perhaps for go(0)
    How should the UI work? If shadow-iframe loads page X and then Y is loaded there, what should back button do? I guess nothing. That shouldn't be too bad. The shadow-iframe container component could manually call push/replaceState when needed, or shadow-iframe.src = "some new page"

    Given the recent example, bug in Google Ads where their scripts caused the container page to go back, I'd prefer to never expose history state even in open case, but at least in closed case the state shouldn't be shared.

  5. annevk commented on Feb 17, 2016

    @annevk
    Collaborator

    I would be okay with blocking history from "shadow-iframe" by default. And then later figuring out if we want to make that work. @hayatoito @rniwa?

  6. annevk commented on Feb 17, 2016

    @annevk
    Collaborator

    I'm not sure if throwing would be best by the way. It depends on what kind of things end up being embedded. If you throw a bunch of existing pages will likely break when embedded in this way.

  7. smaug---- commented on Feb 17, 2016

    @smaug----

    but if the page called go(<not_zero>), it sure would expect something to happen, and if we wouldn't throw, the page would be broken in some other way.
    Or pushState(). After that one would expect history.state to be the thing passed to pushState.

    This is tricky, but I'm not sure we have any other good option to effectively disable all history API in shadow-iframes.
    Hmmm, crazy idea. Could we actually hide History interface and .history propery in the browsing contexts under shadow-iframes?

  8. hayatoito commented on Mar 15, 2016

    @hayatoito
    ContributorAuthor

    I would be okay with blocking history from "shadow-iframe" by default. And then later figuring out if we want to make that work. @hayatoito @rniwa?

    I am okay with this. Blocking history from "shadow-iframe" by default should be a safe option.

    [Updated] On the second thought, go() should work, IMO. Let me think further.

  9. hayatoito commented on Mar 15, 2016

    @hayatoito
    ContributorAuthor

    My opinion is:

    • iframes in a shadow tree does not have any affect on window.history. Thus, states of iframes in a shadow trees is not exposed to window.history. In other words, window.history is owned exclusively by a document tree.
    • go() should work as usual.

    We might want to have another APIs, such as DocumentOrShadowRoot.history, if we want to make that work somehow later.

  10. annevk commented on Mar 15, 2016

    @annevk
    Collaborator

    How can go() work if such <iframe>s don't have an effect on the history?

  11. hayatoito commented on Mar 15, 2016

    @hayatoito
    ContributorAuthor

    go() works in a history of a document tree. So I guess calling window.history.go() from a (developer of) shadow tree is a bad practice and does not bring a desired behavior in most cases.

  12. smaug---- commented on Mar 15, 2016

    @smaug----

    To be a tad more precise, go() works in browsing context tree.

    Not putting shadow dom iframe loads to session history, but having go() to work would lead to very surprising behavior. The browsing context in iframe could expect its page loads are in session history, but go() wouldn't actually know about those loads so it would always affect to some ancestor or sibling browsing context, never the browsing context in iframe.

    (go() is super error prone API to use :/ )

  13. hayatoito commented on Apr 1, 2016

    @hayatoito
    ContributorAuthor

    Yeah, I think we can not have a perfect solution here. We have to compromise for window.history because it's globally accessible.

  14. 75 remaining items

  15. rniwa commented on Dec 3, 2017

    @rniwa
    Collaborator

    We didn't have a time to discuss it at TPAC 2017.

  16. smaug---- commented on Dec 6, 2017

    @smaug----

    This was discussed at TPAC 2016, and the approach we agreed to try out was going to be implemented in webkit, IIRC, to get more experience on this issue before spec'ing it.

  17. rniwa commented on Dec 6, 2017

    @rniwa
    Collaborator

    Yeah, sorry, I haven't had a time to implement it. If Gecko or some other engine is interested in implementing the proposed approach, please move ahead & give us any feedback.

  18. annevk commented on Dec 7, 2017

    @annevk
    Collaborator

    So do you disable <iframe> altogether or are we going to run into compatibility issues?

  19. smaug---- commented on Dec 7, 2017

    @smaug----

    Yeah, I don't know what blink and webkit do now. Probably something somewhat random, which exposes the existence of shadow DOM to the outside world by using the same session history.

    Did anyone take pictures of the plan we draw 2016?
    It was separate session history for shadow iframes, since otherwise iframes in different shadow DOMs could end up affecting each others.

  20. smaug---- commented on Dec 7, 2017

    @smaug----

    But, if there are two iframe in a shadow DOM, should those use the same session history?

  21. rniwa commented on Feb 19, 2018

    @rniwa
    Collaborator

    We're willing to make backwards incompatible changes on our end to match the new spec if any.

  22. rniwa commented on Oct 25, 2018

    @rniwa
    Collaborator

    Here's a strawman proposal:

    1. In the global navigation history, look for the history item where the navigated frame is the new (destination) state.
    2. Rewrite the history items between the current history item and the item found in (1) so that the navigated frame's state is of the destination state.
    3. Insert new history items where all the frames except the navigated frame are identical to that of the current history item, and the navigated frame is of states between the current frame's state and the destination state.
    4. Navigate back to the new state created in (3) which matches the destination state.
  23. marcoscaceres commented on Oct 25, 2018

    @marcoscaceres

    screenshot 2018-10-25 10 14 13

    screenshot 2018-10-25 10 14 32

  24. rniwa commented on Oct 25, 2018

    @rniwa
    Collaborator

    TPAC F2F Consensus / action item: Take back the above proposal and see each browser engine can implement it or not.

  25. raegen commented on Apr 6, 2023

    @raegen
  26. added a commit that references this issue on Jul 30, 2025
    08793be
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions