Open Bug 1981019 Opened 11 months ago Updated 9 months ago

browser.navigation.requireUserInteraction (Back button intervention) breaks pushState()

Categories

(Core :: DOM: Core & HTML, defect)

Firefox 143
defect

Tracking

()

UNCONFIRMED

People

(Reporter: sdaniele3, Unassigned, NeedInfo)

Details

Steps to reproduce:

Confirmed on Firefox Nightly 143. I think requireUserInteraction has shipped to Stable / Main, but I'm normally on ESR releases so haven't hit it in my day-to-day yet.

Save this as a .html file and open it in Firefox (or Chrome or Edge or Brave).

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script>
function hashTest(event) {
  let newHash = event.newURL.split('#')[1];
  if (newHash == 'goto1') {
    window.history.replaceState({'url': '#inject'}, '', '#inject');
    window.history.pushState({'url': '#' + newHash}, '', '#' + newHash);
  }
}
window.addEventListener('hashchange', hashTest);

</script>
</head>

<body>
<a href="#goto1">Goto1</a>
<button onclick="history.back()">history.back() works correctly</button>
</body>
</html>

Actual results:

Click on the "goto1" clink. You will nagivate to "/#goto1". Press the back button. You will navigate to "/".

Expected results:

You should navigate to "/#inject".

Other browsers have had the back button intervention for much longer than Firefox and they allow the behavior in the code. I don't see why Firefox should forbid it.

Component: Untriaged → DOM: Core & HTML
Product: Firefox → Core
Summary: browser.navigation.requireUserInteraction (Back button intervention) breaks pushState() [works on Chrome + Brave + Edge] → browser.navigation.requireUserInteraction (Back button intervention) breaks pushState()

Adam, do you have an idea of why this is happening?

Flags: needinfo?(avandolder)

Hi, we also hit a similar issue at Google. For example, with this file:

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script>
function test() {
  window.history.replaceState(0, '', '#0');
  window.history.pushState(1, '', '#1');
  window.history.pushState(2, '', '#2');
  window.history.pushState(3, '', '#3');
  window.history.go(-2);
}
</script>
</head>

<body>
<button onclick="test()">Run test</button>
</body>
</html>

And click on the button.

Expected: [0, 1*, 2, 3]
Actual: [0, 1*, 3] and 2 is missing

And then if back or forward button is clicked, even "1" is gone, and the history becomes:

[0*, 3] or [0, 3*]

This is different from Chrome or Safari.

However, after turning off browser.navigation.requireUserInteraction in about:config, it's working as expected again.

You need to log in before you can comment on or make changes to this bug.