The window.appHistory API provides the ability to intercept navigations as well as introspect an application's history entries. This provides a more useful alternative to window.history, specifically aimed at the needs of single-page web applications.
Interoperability and Compatibility
The biggest interoperability risk with this API is that it is building on a rocky foundation. The existing session history spec does not match browsers very well, and browsers do not match each other. Since this new API layers on top of the existing model, this could cause issues.
We plan to address this by having solid and well-tested specifications for all aspects of the new API, as well as every way the new API integrates with window.history. Additionally, we're working in parallel to improve interoperability on the base model through spec updates, writing web platform tests, and fixing browser bugs.Gecko
: No signal (https://github.com/mozilla/standards-positions/issues/543
) Initial positive opinions on the issue, but not yet an official positionWebKit
: No signal (https://lists.webkit.org/pipermail/webkit-dev/2021-September/031987.html
: Strongly positive (https://github.com/WICG/proposals/issues/20
) The initial public proposal, as well as the issue tracker and Twitter, has had great engagement and enthusiasm from developers. In addition, we have several conversations going on with frameworks, libraries, and larger websites to ensure that we're solving the problems they see with today's history API.
Although this API layers onto the same underlying model as window.history, and will have well-specified interactions with it, the exact integrations may be confusing. (For example, appHistory.navigate() will behave differently from history.pushState().) We'll do our best to smooth over these rough edges where possible, but will favor making the app history API pleasant to use over making it perfectly align with window.history.
From a performance standpoint, there are some potential challenges regarding exposing information and intercepting navigations that are usually handled in the browser process to the renderer process, and ensuring everything stays synchronized. We will explore this further as we prototype.
This feature is hard to polyfill, but developers have managed to produce something that works in many cases: https://github.com/frehner/appHistory
We've also seen a pattern where developers have existing history wrappers (e.g. router libraries or app-specific history code) which they can adapt with a new app history-based backend for browsers that support it.
We believe the security risks of this feature are minimal because of how it is scoped to same-origin contiguous history entries, and similarly only allows interception of same-origin navigations. We also need to ensure that we don't allow "trapping" the user by preventing them from using their back button; the API is designed to prevent this.