I'm running into a timeout error when using Puppeteer to navigate to a heavy website with lots of videos. I've increased the timeout to 690000 ms using page.goto(), and set the default navigation timeout to 0 using page.setDefaultNavigationTimeout(), but I'm still getting the following error:
CAUGHT AN ERROR TimeoutError: Navigation timeout of 90000 ms exceeded at LifecycleWatcher._LifecycleWatcher_createTimeoutPromise (C:\Users\Aliyan Malik\Desktop\Moniter System CRC\node_modules\puppeteer-core\lib\cjs\puppeteer\common\LifecycleWatcher.js:162:12)
Here's my code:
const express = require("express");
const app = express();
const puppeteer = require("puppeteer");
let timer;
async function checkSite() {
let browser;
try {
console.log("TEST SCRIPT STARTED...");
browser = await puppeteer.launch({
headless: false,
// timeout: 990000,
// protocolTimeout: 990000,
});
const page = await browser.newPage();
await page.setDefaultNavigationTimeout(0);
await page.goto("https://www.crcmedia.com/", {
timeout: 690000,
waitUntil: "domcontentloaded",
});
// await page.waitForNavigation({
// timeout: 690000,
// waitUntil: "domcontentloaded",
// });
await page.waitForSelector("custom-gallery");
const videoTags = await page.evaluate(() => {
const customGallery = document.getElementsByTagName("custom-gallery")[0];
const shadowHost = customGallery.shadowRoot;
const videoElements = shadowHost.querySelectorAll("video");
return Array.from(videoElements);
});
console.log("VIDEO TAGS", videoTags);
for (let i = 0; i < videoTags.length; i++) {
console.log("I", i);
const video = videoTags[i];
await video.hover();
const isHovered = await page.evaluate(() => {
const video = document.querySelector("video");
return video === document.activeElement;
});
await video.click();
const isClicked = await page.evaluate(() => {
const video = document.querySelector("video");
return video.paused === false;
});
if (isHovered && isClicked) {
console.log(`Video ${i + 1} interactions working properly`);
} else {
console.log(`Video ${i + 1} interactions not working properly`);
}
}
} catch (error) {
console.error("CAUGHT AN ERROR", error);
}
if (browser) {
await browser.close();
}
}
app.get("/", (req, res) => {
res.send("Site monitoring is running");
// timer = setInterval(checkSite, 60 * 60 * 1000); // Run checkSite function every hour
checkSite().catch((error) => console.error("ERROR RUNNING CHECKSITE", error));
});
app.listen(3000, () => {
console.log("Server is running on port 3000");
checkSite().catch((error) => console.error("ERROR RUNNING CHECKSITE", error));
});
Is there something else I can do to increase the timeout or make the navigation more efficient? Any help would be greatly appreciated. Thank you!
"I increased the timeout setting for my Puppeteer script to 690000 milliseconds to account for the website's heavy video content. I also set the setDefaultNavigationTimeout method to 0 to disable the default timeout. Despite these adjustments, I continue to receive the Navigation timeout of 90000 ms exceeded error."