0

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.

Tanner Helton
  • 89
  • 1
  • 1
  • 12
  • `waitForNavigation()` seems misplaced here. I'd just remove it--there's no navigation to wait for unless you're clicking on a link or something. Anyway, I can't run this code. Please provide a [mcve]. – ggorlen Jul 08 '22 at 22:13
  • @ggorlen the `waitForNavigation()` is for the `goto()` that proceeds it. Not sure why, but it works with it but not without, so maybe it has something to do that that? I'm new here, so your guess is better than mine! – Tanner Helton Jul 11 '22 at 14:07
  • `goto()` already waits for navigation though. There'd have to be some additional redirect for `waitForNavigation()` to not fail, as far as I can tell. [This post](https://stackoverflow.com/questions/72922540/iterating-through-a-list-of-urls-with-puppeteer/72924503#72924503) from the other day has the same problem. If you don't mind adding a [mcve] I can take a look, otherwise I'm just repeating my comment again here. – ggorlen Jul 11 '22 at 15:53

0 Answers0