puppeteer: [Bug]: ProtocolError: Target.createTarget timed out. Increase the 'protocolTimeout' setting in launch/connect calls for a higher timeout if needed.

Bug expectation

I’m trying to run my server on Render, I configure the docker file so pupetter works correctly. But when I deploy the code on Render I faced with related error. How can I solve this? I increase all time but does not work.

`

async function getResults(lnk) {
  const results = [];
  const timeFrames = [1, 5, 15];

  
  const browser = await puppeteer.launch({
    headless: 'new',
    args: [
      "--disable-setuid-sandbox",
      "--no-sandbox",
      "--single-process",
      "--no-zygote",
    ],
    protocolTimeout: 240000,// 60 saniye olarak ayarlanmıştır

    executablePath:
      process.env.NODE_ENV === "production"
        ? process.env.PUPPETEER_EXECUTABLE_PATH
        : puppeteer.executablePath(),
  });
  const page = await browser.newPage();
  // await page.setDefaultNavigationTimeout(0);

  for (const i of timeFrames) {
    const page = await browser.newPage();
    const url = `${lnk}?timeFrame=${i * 60}`;
    console.log(`Getting: ${url}`);

    await page.goto(url, { waitUntil: ["domcontentloaded"],timeout: 100000  });
    await page.waitForSelector("section.forecast-box-graph .title",{timeout: 10000});
    // await page.waitForSelector('h1.main-title.js-main-title');


    const status = await page.$eval(
      "section.forecast-box-graph .title",
      (el) => el.textContent
    );
    const Bank_Name = await page.$eval("h1.main-title.js-main-title", (el) =>
      el.textContent.trim()
    );
    results.push(status);

    await page.close();
  }

  await browser.close();
  results.push(lnk.split("/").pop().split("-").join(" "));

  return results;
}

async function scrape() {
  while(true){
    for (const lnk of Link_Lst) {
      const results = await getResults(lnk);
      console.log("getting result:",results);
      if(results.includes("Strong Sell")){
        console.log("HERE");
        if (Sell_) {
              sendAlertToTG(`Alert for Bank ${results.slice(-1)} - "STRONG SELL"`);
              Sell_ = false;
            }
      }
      if(results.includes("Strong Buy")){
        if (Buy_) {
              sendAlertToTG(`Alert for Bank ${results.slice(-1)} - "STRONG BUY"`);
              Buy_ = false;
            }    
          }
  

    }
  
    console.log("\n\nWaiting for___10___Seconds");
    waitBeforeNextIteration(10000);
  
  }
}
function waitBeforeNextIteration(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}
scrape();

`

Bug behavior

  • Flaky
  • PDF

Minimal, reproducible example

None

Error string

ProtocolError: Target.createTarget timed out. Increase the 'protocolTimeout' setting in launch/connect calls for a higher timeout if needed. May 8 06:40:29 PM at new Callback (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:61:35) May 8 06:40:29 PM at CallbackRegistry.create (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:106:26) May 8 06:40:29 PM at Connection._rawSend (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:216:26) May 8 06:40:29 PM at Connection.send (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:210:21) May 8 06:40:29 PM at CDPBrowser._createPageInContext (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Browser.js:273:94) May 8 06:40:29 PM at CDPBrowserContext.newPage (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Browser.js:541:78) May 8 06:40:29 PM at CDPBrowser.newPage (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Browser.js:267:78) May 8 06:40:29 PM at getResults (/usr/src/app/index.js:78:32) May 8 06:40:29 PM at async scrape (/usr/src/app/index.js:174:23) May 8 06:40:29 PM May 8 06:40:29 PM Node.js v18.16.0 May 8 06:40:39 PM /usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:61 May 8 06:40:39 PM _Callback_error.set(this, new Errors_js_1.ProtocolError()); May 8 06:40:39 PM ^ May 8 06:40:39 PM May 8 06:40:39 PM ProtocolError: Protocol error (Target.createTarget): Target closed May 8 06:40:39 PM at new Callback (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:61:35) May 8 06:40:39 PM at CallbackRegistry.create (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:106:26) May 8 06:40:39 PM at Connection._rawSend (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:216:26) May 8 06:40:39 PM at Connection.send (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:210:21) May 8 06:40:39 PM at CDPBrowser._createPageInContext (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Browser.js:273:94) May 8 06:40:39 PM at CDPBrowserContext.newPage (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Browser.js:541:78) May 8 06:40:39 PM at CDPBrowser.newPage (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Browser.js:267:78) May 8 06:40:39 PM at getResults (/usr/src/app/index.js:74:30) May 8 06:40:39 PM at process.processTicksAndRejections (node:internal/process/task_queues:95:5) May 8 06:40:39 PM at async scrape (/usr/src/app/index.js:174:23) May 8 06:40:39 PM May 8 06:40:39 PM Node.js v18.16.0

Puppeteer configuration

const browser = await puppeteer.launch({
    headless: 'new',
    args: [
      "--disable-setuid-sandbox",
      "--no-sandbox",
      "--single-process",
      "--no-zygote",
    ],
    protocolTimeout: 240000,// 60 saniye olarak ayarlanmıştır

    executablePath:
      process.env.NODE_ENV === "production"
        ? process.env.PUPPETEER_EXECUTABLE_PATH
        : puppeteer.executablePath(),
  });

This is my dockerfile:

FROM ghcr.io/puppeteer/puppeteer:20.1.2


ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD=true \
    PUPPETEER_EXECUTABLE_PATH=/usr/bin/google-chrome-stable

WORKDIR /usr/src/app

COPY package*.json ./
RUN npm ci
COPY . .
CMD [ "node", "index.js" ]

Puppeteer version

20.1.2

Node version

v16.15.0

Package manager

npm

Package manager version

1.0.0

Operating system

macOS

About this issue

  • Original URL
  • State: closed
  • Created a year ago
  • Reactions: 5
  • Comments: 19

Most upvoted comments

Saw your is

Is there any suggestion for me?

The error message is indicating that there is a timeout issue with the ‘createTarget’ method in the Puppeteer library. The recommended solution is to increase the ‘protocolTimeout’ setting in the launch/connect calls to allow for a longer timeout if needed. The error also includes information about a protocol error with the ‘Target.createTarget’ method causing it to close, potentially due to the timeout issue.

What is the version of /usr/bin/google-chrome-stable?

The error message is telling you that there was a timeout while trying to create a new target in Puppeteer. Specifically, the Target.createTarget method timed out. The suggested solution is to increase the protocolTimeout setting in the launch() or connect() method.

You already have protocolTimeout set to 240000 (4 minutes), which should be enough. Therefore, there may be another issue causing the problem.

One possible cause is that your script is opening too many pages without closing them. Puppeteer has a limit on the number of pages that can be opened at once, and exceeding that limit can cause issues.

To fix this, you should close each page after you’re done with it, by calling page.close().

Another possible cause is that the page you’re trying to open is taking too long to load, and eventually times out. You can try increasing the timeout for page.goto() by passing a higher value to the timeout option, like this:

await page.goto(url, { waitUntil: “domcontentloaded”, timeout: 30000 });

This will set the timeout to 30 seconds, which may be enough for your page to load.

Finally, you can try adding some error handling code to your getResults() function, to catch any errors that occur during page navigation or scraping. Here’s an example:

try { const status = await page.$eval( “section.forecast-box-graph .title”, (el) => el.textContent ); const Bank_Name = await page.$eval(“h1.main-title.js-main-title”, (el) => el.textContent.trim() ); results.push(status); } catch (error) { console.error(“Error getting results:”, error); }

await page.close(); This will catch any errors that occur while evaluating the page selectors, and print an error message to the console.

Saw your is

Is there any suggestion for me?

The error message is indicating that there is a timeout issue with the ‘createTarget’ method in the Puppeteer library. The recommended solution is to increase the ‘protocolTimeout’ setting in the launch/connect calls to allow for a longer timeout if needed. The error also includes information about a protocol error with the ‘Target.createTarget’ method causing it to close, potentially due to the timeout issue.

If you notice, I said that I increased this timeout value. However, it doesn’t work. protocolTimeout: 240000 and I increase it didnt work.

Hey, having the same issue here with headless: false mode.

This error only occurs about 10% of the time (running Puppeteer on AWS Lambda with virtual displays): Target.createTarget timed out. Increase the 'protocolTimeout' setting in launch/connect calls for a higher timeout if needed.

Solved this mostly by just letting it crash and implementing a retry-loop. Chrome usually launches correctly on the 2nd or 3rd try. Both the browser and the tab has to successfully be opened, otherwise it may throw a random error later when opening the tab, in my experience.

Seems like the error randomly occurs, and I haven’t been able to trace it or reproduce it consistently. But using a retry loop seems to have solved 99% of cases on our side, where we had 80-90% success before. It is just a bit slower sometimes, but it works, so whatever.

If someone finds a clean solution, please share! 😃

Here is the code we used to solve most issues with this timeout error. Hope it helps someone.

// Attempt to open Chrome browser 5 times maximum.
let browser: Browser | null = null;
let firstTab: Page | null = null;
const browserStartAttempts = 5;
for(let i = 0; i < browserStartAttempts; i++) {
    try {
        logger.info(`Starting Chrome (attempt ${i+1}/${browserStartAttempts})...`)
        browser = await puppeteer.launch({
            headless: false,
            ignoreHTTPSErrors: true,
            defaultViewport: null,
            ignoreDefaultArgs: ['--enable-automation'],
            args: [
                '--disable-infobars',
                '--no-sandbox',
                '--disable-setuid-sandbox',
                '--disable-gpu=False',
                '--enable-webgl',
                '--window-size=1600,900',
                '--start-maximized',
    
                // Args for AWS Lambda:
                '--single-process',
                '--user-data-dir=/tmp/user-data',
                '--data-path=/tmp/data-path',
                '--homedir=/tmp',
                '--disk-cache-dir=/tmp/cache-dir',
                '--database=/tmp/database',
            ],
            timeout: 10_000, // 10 seconds
            protocolTimeout: 20_000, // 20 seconds
            ...options,
        });
        await sleep(1000);
        logger.info("Chrome started...")
    
        logger.info("Opening first tab...")
        firstTab = await browser.newPage();
        break;
    } catch(err) {
        logger.info("Error when starting Chrome...")
        logger.info(err)
        if(browser && browser.connected) {
            logger.info("Closing browser...")
            await browser.close();
        }
        await sleep(1000);
        browser = null;
        firstTab = null;
        logger.info("Trying again...\n\n");
    }
}

We are having the same issue in production which only started happening recently using the latest versions of Chromium. Our issue has allegedly been resolved as we were missing a page.close() that resulted in lots (thousands) of open tabs before throwing errors.

I believe the OP @hobik has the same issue with large numbers of tabs being open. The posted code appears to be missing an await to wait 10 seconds before restarting the loop which might be the cause:

async function scrape() {
  while(true){
    for (const lnk of Link_Lst) {
      const results = await getResults(lnk);
      console.log("getting result:",results);
      if(results.includes("Strong Sell")){
        console.log("HERE");
        if (Sell_) {
              sendAlertToTG(`Alert for Bank ${results.slice(-1)} - "STRONG SELL"`);
              Sell_ = false;
            }
      }
      if(results.includes("Strong Buy")){
        if (Buy_) {
              sendAlertToTG(`Alert for Bank ${results.slice(-1)} - "STRONG BUY"`);
              Buy_ = false;
            }    
          }
  

    }
  
    console.log("\n\nWaiting for___10___Seconds");
-    waitBeforeNextIteration(10000);
+    await waitBeforeNextIteration(10000);  
  }
}
function waitBeforeNextIteration(ms) {
  return new Promise(resolve => setTimeout(resolve, ms));
}
scrape();

This issue was not reproducible. Please check that your example runs locally and the following:

  • Ensure the script does not rely on dependencies outside of puppeteer and puppeteer-core.
  • Ensure the error string is just the error message.
    • Bad:

      Error: something went wrong
        at Object.<anonymous> (/Users/username/repository/script.js:2:1)
        at Module._compile (node:internal/modules/cjs/loader:1159:14)
        at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
        at Module.load (node:internal/modules/cjs/loader:1037:32)
        at Module._load (node:internal/modules/cjs/loader:878:12)
        at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
        at node:internal/main/run_main_module:23:47
      
    • Good: Error: something went wrong.

  • Ensure your configuration file (if applicable) is valid.
  • If the issue is flaky (does not reproduce all the time), make sure ‘Flaky’ is checked.
  • If the issue is not expected to error, make sure to write ‘no error’.

Once the above checks are satisfied, please edit your issue with the changes and we will try to reproduce the bug again.


Analyzer run