I found delay a bit short:
await window.delay(1000);
//await window.delay(150);
Other fix for pages sometimes not firing load event
// Added to prevent stopping
async function gotoWithRetry(page, url, options, retries = 5, timeout = 10000) {
let attempts = 0;
while (attempts < retries) {
try {
// Start navigation
const response = await Promise.race([
page.goto(url, options), // Attempt to go to the URL
new Promise((_, reject) => setTimeout(() => reject(new Error('Timeout')), timeout)) // Timeout promise
]);
// Check if the response is valid
if (response && response.ok()) {
//console.log('Page loaded successfully!');
return; // Successfully loaded the page
} else {
throw new Error('Failed to load the page.');
}
} catch (error) {
attempts++;
console.error(`Attempt ${attempts} failed: ${error.message}`);
if (attempts === retries) {
throw new Error(`Failed to load the page after ${retries} attempts.`);
}
console.log('Retrying...');
}
}
I found delay a bit short: await window.delay(1000); //await window.delay(150);
Other fix for pages sometimes not firing load event // Added to prevent stopping async function gotoWithRetry(page, url, options, retries = 5, timeout = 10000) { let attempts = 0; while (attempts < retries) { try { // Start navigation const response = await Promise.race([ page.goto(url, options), // Attempt to go to the URL new Promise((_, reject) => setTimeout(() => reject(new Error('Timeout')), timeout)) // Timeout promise ]);
}
replace
await gotoWithRetry(page, url, { waitUntil: 'load' }); //await page.goto(url, { waitUntil: "load" });