Merge pull request #1330 from bershanskiy/history

Use Navigation API when available
This commit is contained in:
Ajay Ramachandran
2022-06-02 02:30:57 -04:00
committed by GitHub
3 changed files with 53 additions and 7 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");
}
});