From d8dfbef1a719640d070437f16366bf962980f951 Mon Sep 17 00:00:00 2001 From: Ajay Date: Thu, 21 Jul 2022 15:14:57 -0400 Subject: [PATCH] Fix issue with navigator triggering events before document.url updates --- src/content.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/content.ts b/src/content.ts index b7fb30dd..92b59eca 100644 --- a/src/content.ts +++ b/src/content.ts @@ -1044,8 +1044,8 @@ function startSkipScheduleCheckingForStartSponsors() { } } -function getYouTubeVideoID(document: Document): string | boolean { - const url = document.URL; +function getYouTubeVideoID(document: Document, url?: string): string | boolean { + url ||= document.URL; // clips should never skip, going from clip to full video has no indications. if (url.includes("youtube.com/clip/")) return false; // skip to document and don't hide if on /embed/ @@ -2205,7 +2205,8 @@ function checkForPreloadedSegment() { 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))); + (window as unknown as { navigation: EventTarget }).navigation.addEventListener("navigate", (e) => + videoIDChange(getYouTubeVideoID(document, (e as unknown as Record>).destination.url))); } // Record availability of Navigation API