I'm having a problem with Puppeteer where I run one set of code and it works fine for a website, but then if I run the same code for another website running the same platform it doesn't work as expected. I'm using the two websites https://www.toyotaofcedarpark.com/ and https://www.toyotaofnaperville.com/ both of which are made with Dealer Inspire
This code works on https://www.toyotaofnaperville.com/ but not https://www.toyotaofcedarpark.com/ (I receive a timeout error)
index.js
var link = await scraperFunctions.getInventoryLink(page, category);
console.log("Found inventory link:", link);
await page.goto(link);
await page.waitForNavigation();
var postedVehicles = await scraperFunctions.postedVehicles(page, category);
console.log(postedVehicles, ": NUM VEHICLES");
postedVehicles.js
async function postedVehicles(page, category) {
switch (category) {
case 0:
return category0(page);
case 1:
return category1(page);
case 2:
return category2(page);
}
}
async function category0(page) {
return await page.$eval("span#results-title", (elem) =>
elem.innerText.replace(/\D/g, "")
);
}
module.exports = postedVehicles;
Yet, when I remove the await page.waitForNavigation();
line from index.js it works for https://www.toyotaofcedarpark.com/ but not https://www.toyotaofnaperville.com/ (I receive a Error: Execution context was destroyed, most likely because of a navigation.