diff options
author | Ajay <[email protected]> | 2023-12-13 19:38:38 -0500 |
---|---|---|
committer | Ajay <[email protected]> | 2023-12-13 19:38:38 -0500 |
commit | a8cd2357e70886f390525d989d06d9a5c563162d (patch) | |
tree | 2b09de2ad2f6e12504a52b9dcb338c35deadf498 /src | |
parent | 0a4728ec5ed044048a3005c0f2c4865d13b0b093 (diff) | |
download | SponsorBlock-a8cd2357e70886f390525d989d06d9a5c563162d.tar.gz SponsorBlock-a8cd2357e70886f390525d989d06d9a5c563162d.zip |
Add retry logic to popup info
Diffstat (limited to 'src')
-rw-r--r-- | src/popup.ts | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/src/popup.ts b/src/popup.ts index a6157dea..562fbfcb 100644 --- a/src/popup.ts +++ b/src/popup.ts @@ -94,6 +94,8 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> { type PageElements = { [key: string]: HTMLElement } & InputPageElements let stopLoadingAnimation = null; + // For loading video info from the page + let loadRetryCount = 0; //the start and end time pairs (2d) let sponsorTimes: SponsorTime[] = []; @@ -409,9 +411,18 @@ async function runThePopup(messageListener?: MessageListener): Promise<void> { currentVideoID = result.videoID; loadTabData(tabs, updating); - } else if (result === undefined && chrome.runtime.lastError) { - //this isn't a YouTube video then, or at least the content script is not loaded + } else { + // Handle error if it exists + chrome.runtime.lastError; + + // This isn't a YouTube video then, or at least the content script is not loaded displayNoVideo(); + + // Try again in some time if a failure + loadRetryCount++; + if (loadRetryCount < 6) { + setTimeout(() => getSegmentsFromContentScript(false), 100 * loadRetryCount); + } } }); } |