Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

arturovt
Copy link
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`. ' +
Copy link
Contributor Author

@arturovt arturovt Jun 21, 2025

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant