Skip to content

document.open() can make a document's URL go out of sync with its history entry #3885

@TimothyGu

Description

@TimothyGu

Currently, the document open steps has

Change document's URL to the URL of the responsible document specified by the entry settings object.

However, it doesn't change the URL of its history entry.

@domenic and @rniwa agree that this is a pretty bad behavior. In particular, it breaks fragment navigation as currently spec'd, as well as some implementor expectation [1].

More visibly, this results in different behaviors when reloading a page that has been document.open()ed from another document:

  • Edge and Firefox are currently immune to this problem as they implement the reload override flag, proposed to be removed in Tracking issue for document.open() overhaul #3818
  • Chrome when reloading uses the URL of the current history entry. This will cause the document.open()ed document to go back to its original URL [1].
  • Safari when reloading uses the URL of the document (which is what location.reload() is spec'd to do). This will cause the document.open()ed document to go to the URL of outer document that called document.open().

With the constraint that we want to retain the URL-setting behavior of document.open(), we see two paths of going forward:

  • To preserve Safari reloading behavior:
    In document.open(): set the current history entry's URL to the new URL as well. This will make a reload go to that new URL.
  • To preserve Chrome reloading behavior:
    In document.open(): set the current history entry's URL to the new URL as well; save the original URL in the Document.
    In location.reload(): use that original URL for reloading, if it's present.

We prefer the first as it is significantly simpler to spec, and perhaps also to implement. Opinions?

/cc @smaug---- @bzbarsky

[1]: Chrome used to follow Safari's behavior, but during an internal refactoring location.reload() is made to use the history entry's URL rather than the document's URL under the assumption that they are the same. See chromium/chromium@cf62ba4.

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