It was more noticed as an apparent gap in the existing API rather than something that came from personal need on a project. Arguably any usecase could also work by getting the <link rel="canonical">
tag however location.canonical
is a clearer alternative to document.querySelector("link[rel='canonical']").href
and is shorter and cleaner once you take into account null checking on the link element before accessing href
.
As mentioned an API like this could also take into account a canonical HTTP header which is not taken into account by the link element.
Some example usecases would be:
An analytics script. Just as canonical URLs are helpful in terms on SEO by not splitting pagerank on duplicate pages they would be as helpful in not splitting results in analytics reports, as well as tracking down referrals that may link in to non-canonical versions of a URL.
Sharing scripts (particularly with web share on the way) could easily be set to share the canonical version of a page rather than the current page (as opposed to eg AMP or mobile versions of a page).
User scripts or extensions to automatically break out of AMP or mobile pages from links could easily discover and reload the page at the canonical URL.