Skip to content

fix(router): handle scrollRestoration error in restricted environments - #62186

Closed
arturovt wants to merge 1 commit into
angular:mainfrom
arturovt:fix/router-scroll-position-restoration
Closed

arturovt wants to merge 1 commit into
angular:mainfrom
arturovt:fix/router-scroll-position-restoration

Conversation

@arturovt

Copy link
Copy Markdown
Contributor

In this commit, setting window.history.scrollRestoration is wrapped in a try-catch block to prevent SecurityError exceptions in restricted contexts such as:

  • sandboxed iframes
  • partially navigated or inactive windows
  • test runners, extensions, or content previews

If an error occurs, a runtime warning with error code [2400] is logged to the console. This avoids breaking app initialization and improves cross-browser safety.

Unfortunately, it's not possible to perform any end-to-end testing of this fix.

In this commit, setting `window.history.scrollRestoration` is wrapped in a try-catch block to prevent `SecurityError` exceptions in restricted contexts such as:

- sandboxed iframes
- partially navigated or inactive windows
- test runners, extensions, or content previews

If an error occurs, a runtime warning with error code [2400] is logged to the console. This avoids breaking app initialization and improves cross-browser safety.

Unfortunately, it's not possible to perform any end-to-end testing of this fix.
formatRuntimeError(
RuntimeErrorCode.SCROLL_RESTORATION_UNSUPPORTED,
ngDevMode &&
'Failed to set `window.history.scrollRestoration`. ' +

@arturovt arturovt Jun 21, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@atscott as discussed in Slack -- let me know if this message needs to be updated.

@ngbot ngbot Bot added this to the Backlog milestone Jun 21, 2025
@thePunderWoman
thePunderWoman requested review from atscott and removed request for thePunderWoman June 23, 2025 08:17

@atscott atscott left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reviewed-for: public-api

@pullapprove
pullapprove Bot requested a review from devversion June 23, 2025 16:12

@AndrewKushnir AndrewKushnir left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed-for: public-api

@thePunderWoman thePunderWoman added action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release labels Jun 24, 2025
thePunderWoman pushed a commit that referenced this pull request Jun 24, 2025
#62186)

In this commit, setting `window.history.scrollRestoration` is wrapped in a try-catch block to prevent `SecurityError` exceptions in restricted contexts such as:

- sandboxed iframes
- partially navigated or inactive windows
- test runners, extensions, or content previews

If an error occurs, a runtime warning with error code [2400] is logged to the console. This avoids breaking app initialization and improves cross-browser safety.

Unfortunately, it's not possible to perform any end-to-end testing of this fix.

PR Close #62186
@thePunderWoman

Copy link
Copy Markdown
Contributor

This PR was merged into the repository by commit 7600bec.

The changes were merged into the following branches: main, 20.0.x

@arturovt
arturovt deleted the fix/router-scroll-position-restoration branch June 24, 2025 12:45
@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Jul 25, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: router target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants