Bug 196989 - Parent window's `history.state` is set to `null` when `history.pushState` is called by a child iframe
Summary: Parent window's `history.state` is set to `null` when `history.pushState` is ...
Status: RESOLVED DUPLICATE of bug 196990
Alias: None
Product: WebKit
Classification: Unclassified
Component: Frames (show other bugs)
Version: Safari 12
Hardware: Mac macOS 10.14
: P2 Normal
Assignee: Nobody
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-04-16 15:01 PDT by Atticus White
Modified: 2019-04-16 15:11 PDT (History)
0 users

See Also:


Attachments
Reproducible output example (271.92 KB, image/png)
2019-04-16 15:01 PDT, Atticus White
no flags Details
Reproducible snippet runnable on bugs.webkit.org (973 bytes, text/plain)
2019-04-16 15:04 PDT, Atticus White
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Atticus White 2019-04-16 15:01:11 PDT
Created attachment 367577 [details]
Reproducible output example

When an `iframe` calls `window.history.pushState`, the parent window's `window.history.state` becomes replaced with a `null` value.

Steps to reproduce:
1. Give the top page a `history.state` value (eg, call `window.history.pushState({something}, 'something')`)
2. In an iframe, perform `window.history.pushState(...)`
3. In the top page, observe that `history.state` has become set to `null`

Expected behavior:
The top page's `history.state` would remain untouched.


Here's a minimal reproducible example that can be ran in the JS console on `bugs.webkit.org` directly:

```
(() => {
  const logHistoryStates = (frame) => {
    console.log('[top] window.history.state', window.history.state);
    console.log('[iframe] window.history.state', frame.contentWindow.history.state);
  };

  // Create a mock state
  window.history.pushState({hello: 'world'}, 'mock bugs.webkit.org history state')

  // Append an iframe with the same origin
  var iframe = document.createElement('iframe');
  iframe.src = 'https://bugs.webkit.org';
  document.body.appendChild(iframe);

  // Take a look at the current `history.state` values for both the page and iframe.
  logHistoryStates(iframe);

  // Let the iframe load, and then simulate a `history.pushState`
  setTimeout(() => {
    console.log('[iframe] history.pushState')
    iframe.contentWindow.history.pushState({foo: 'bar'}, 'mock iframe history state change');

    // Observe the parent window's `history.state` has been corrupted
    logHistoryStates(iframe);
  }, 1000);
})()
```

Attached is a screenshot of the output differences between Safari and Chrome.
Comment 1 Atticus White 2019-04-16 15:04:49 PDT
Created attachment 367578 [details]
Reproducible snippet runnable on bugs.webkit.org
Comment 2 Atticus White 2019-04-16 15:11:37 PDT

*** This bug has been marked as a duplicate of bug 196990 ***