Use History API when available

This commit is contained in:
Anton Bershanskiy
2022-05-25 00:13:02 +03:00
parent e948e1e569
commit 9b9ea39260
3 changed files with 52 additions and 8 deletions

View File

@@ -2204,3 +2204,18 @@ function checkForPreloadedSegment() {
Config.forceSyncUpdate("unsubmittedSegments");
}
}
// Register listener for URL change via Navigation API
const navigationApiAvailable = "navigation" in window;
if (navigationApiAvailable) {
// TODO: Remove type cast once type declarations are updated
(window as unknown as { navigation: EventTarget }).navigation.addEventListener("navigate", () => videoIDChange(getYouTubeVideoID(document)));
}
// Record availability of Navigation API
utils.wait(() => Config.local !== null).then(() => {
if (Config.local.navigationApiAvailable !== navigationApiAvailable) {
Config.local.navigationApiAvailable = navigationApiAvailable;
Config.forceLocalUpdate("navigationApiAvailable");
}
});