The function clearWatchLater() is not being invoked after the timeout expires. The code inside the setTimeout() never executes.
const clearWatchLater = () => {
const youtubeBaseUrl = 'https://www.youtube.com';
if (window.location.href === youtubeBaseUrl) {
// Do Something
} else {
window.focus()
window.location.href = youtubeBaseUrl;
setTimeout(() => {
clearWatchLater()
}, 5000);
}
}
Yes, clearWatchLater() will not be invoked.
Because When your else block gets execute you are reloading the page by using window.location.href = youtubeBaseUrl . After reloading the page Javascript call stack gets reinitialized. It will not get any previous task on its stack. SO your setTimeout is not executing.