0

Im using playwright for webscraping and all i sugegstions I could see was to use timeout of 0 to avoid a timeout error. It seemed to work at first but now I again got the timeout error. Am I doing something wrong or is there another way to solve that issue? Thanks

     browser = await playwright.chromium.launch({headless: true});
        const page = await browser.newPage();
        try {
            const p = await page.goto(url, {timeout: 0});
            if (p.status() < 400) { 
                const html = await page.content();
                return html;
            } else {
               return null;
            }
        } catch(err) {
            return err;
        }
learncode
  • 127
  • 6
  • Hey, can you share more info on which version you are using and which commands you are using, also is there any pre-defined timeout as 180seconds timeout as shown in error? – tushi43 Jun 28 '23 at 14:48
  • Im using version: ^1.30.0 for playwright, there is no pre defined timeout and Im scheduling (with node-schedule) once an hour to be run – learncode Jun 29 '23 at 10:27
  • can you please specify the URL, also why is the timeout you have set to 0? – tushi43 Jun 29 '23 at 11:18
  • its just a regular website with train times. I set it to 0 as I saw it as a suggestion for timeout errors – learncode Jun 29 '23 at 11:53

1 Answers1

0

I am suspecting since you are not closing the browser the issue has occurred or it could be returning to something which is not called. I ran your script and it worked fine

    const playwright = require('playwright');
    (async () => {
      let url= "http://google.com"
      browser = await playwright.chromium.launch({headless: true});
      const page = await browser.newPage();
      try {
          const p = await page.goto(url);
          if (p.status() < 400) { 
              const html = await page.content();
              console.log(html);
          } else {
            console.log("page not found");
          }
        await browser.close();
      } catch(err) {
          return err;
      }
    })();

You can check above code execution here: https://try.playwright.tech/

tushi43
  • 60
  • 1
  • 6