Files
ladybird/Tests/LibWeb/Text/input/navigation/iframe-nav-before-load-creates-history-entry.html
Aliaksandr Kalenik 54757e3586 LibWeb: Don't force replace history handling for iframe src changes
The spec's "not completely loaded" check in navigate_an_iframe_or_frame
was applied to all navigations, including attribute-driven src changes.
This caused navigations triggered before the previous page's load event
(e.g. via postMessage during parsing) to replace the history entry
instead of pushing a new one.

Restrict the check to initial insertion only. For subsequent src
attribute changes, always use "auto" so the navigate algorithm's own
logic (navigation_must_be_a_replace) decides the history handling.
2026-04-04 11:30:55 +02:00

31 lines
1.2 KiB
HTML

<!DOCTYPE html>
<script src="../include.js"></script>
<!-- Test: navigating an iframe via src attribute change before the previous page's
load event should create a new history entry (push), not replace the current one.
Regression test for the "not completely loaded" check in navigate_an_iframe_or_frame
incorrectly forcing replace for attribute-driven navigations. -->
<script>
asyncTest(async done => {
const iframe = document.createElement("iframe");
document.body.appendChild(iframe);
let navigatedToB = false;
window.addEventListener("message", event => {
const data = event.data;
if (data === "page-a-ready" && !navigatedToB) {
navigatedToB = true;
// Navigate to page-b immediately, BEFORE page-a's load event fires.
// This should still create a new history entry (push), not replace page-a.
iframe.src = "../../data/iframe-nav-before-load-page-b.html";
} else if (data && data.type === "page-b-ready") {
// page-b reports the iframe's session history entries
println(data.sessionHistory);
done();
}
});
iframe.src = "../../data/iframe-nav-before-load-page-a.html";
});
</script>