Webscraping TimeoutError - browserType.launch: Timeout 180000ms exceeded. Why am I getting it despite using timeout?

254 views Asked by At

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;
        }
1

There are 1 answers

0
tushi43 On

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/