fix: [#1847] Navigation with location.href now adds to history#2074
Open
TrevorBurnham wants to merge 1 commit intocapricorn86:masterfrom
Open
fix: [#1847] Navigation with location.href now adds to history#2074TrevorBurnham wants to merge 1 commit intocapricorn86:masterfrom
TrevorBurnham wants to merge 1 commit intocapricorn86:masterfrom
Conversation
capricorn86
requested changes
Mar 2, 2026
Owner
capricorn86
left a comment
There was a problem hiding this comment.
History should not be changed when inside a window of a DetachedBrowser as there is no navigation happening. The user stays on the same page. For it to work with unit tests, it can fallback to setting the current URL without navigating.
Contributor
Author
But it's already the case that |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1847
Problem
Setting
location.hrefdoesn't incrementhistory.length. Thehrefsetter callsbrowserFrame.goto()→BrowserFrameNavigator.navigate(), which pushes to history for full navigations. However, when using a detached window (e.g.new Window(), the common test scenario),validateFrameNavigation()returnsfalseand the code falls through to a path that only updates the URL viasetURL()without pushing a history entry.Changes
packages/happy-dom/src/browser/utilities/BrowserFrameNavigator.tsvalidateFrameNavigationfallback path (used by detached windows), push a history entry before callingsetURL(), matching the behavior of the normal navigation path.packages/happy-dom/test/history/History.test.tshistory.lengthincreases after settinglocation.hrefon a detached window.