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

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();

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" ]

And this is the dumpio error logs:

    [21:40:0508/181117.410689:ERROR:bus.cc(399)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
May 8 09:11:18 PM  [21:46:0508/181118.422748:ERROR:bus.cc(399)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
May 8 09:11:18 PM  [21:46:0508/181118.423699:ERROR:bus.cc(399)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
May 8 09:11:18 PM  [21:40:0508/181118.455193:ERROR:bus.cc(399)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
May 8 09:11:18 PM  [21:40:0508/181118.455257:ERROR:bus.cc(399)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
May 8 09:11:18 PM  [21:21:0508/181118.604874:ERROR:system_network_context_manager.cc(765)] Cannot use V8 Proxy resolver in single process mode.
May 8 09:11:19 PM  [21:40:0508/181119.040595:ERROR:bus.cc(399)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
May 8 09:11:19 PM  [21:40:0508/181119.041267:ERROR:bus.cc(399)] Failed to connect to the bus: Could not parse server address: Unknown address type (examples of valid types are "tcp" and on UNIX "unix")
May 8 09:11:19 PM  [21:21:0508/181119.042829:ERROR:system_network_context_manager.cc(765)] Cannot use V8 Proxy resolver in single process mode.
May 8 09:11:19 PM  
May 8 09:11:19 PM  DevTools listening on ws://127.0.0.1:36065/devtools/browser/534507b8-8bff-4967-907a-a39d4897f259
May 8 09:11:21 PM  [21:93:0508/181121.222028:ERROR:bus.cc(399)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
May 8 09:11:21 PM  [21:93:0508/181121.222132:ERROR:bus.cc(399)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
May 8 09:11:21 PM  [21:93:0508/181121.222220:ERROR:bus.cc(399)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
May 8 09:11:21 PM  [21:93:0508/181121.222285:ERROR:bus.cc(399)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
May 8 09:11:21 PM  [21:93:0508/181121.222372:ERROR:bus.cc(399)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
May 8 09:11:22 PM  [0508/181122.090203:ERROR:file_io_posix.cc(144)] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq: No such file or directory (2)
May 8 09:11:22 PM  [0508/181122.090313:ERROR:file_io_posix.cc(144)] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq: No such file or directory (2)
May 8 09:11:22 PM  /usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:61
May 8 09:11:22 PM          _Callback_error.set(this, new Errors_js_1.ProtocolError());
May 8 09:11:22 PM                                    ^
May 8 09:11:22 PM  
May 8 09:11:22 PM  ProtocolError: Protocol error (Target.createTarget): Target closed
May 8 09:11:22 PM      at new Callback (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:61:35)
May 8 09:11:22 PM      at CallbackRegistry.create (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:106:26)
May 8 09:11:22 PM      at Connection._rawSend (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:216:26)
May 8 09:11:22 PM      at Connection.send (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Connection.js:210:21)
May 8 09:11:22 PM      at CDPBrowser._createPageInContext (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Browser.js:273:94)
May 8 09:11:22 PM      at CDPBrowserContext.newPage (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Browser.js:541:78)
May 8 09:11:22 PM      at CDPBrowser.newPage (/usr/src/app/node_modules/puppeteer-core/lib/cjs/puppeteer/common/Browser.js:267:78)
May 8 09:11:22 PM      at getResults (/usr/src/app/index.js:79:32)
May 8 09:11:22 PM      at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
May 8 09:11:22 PM      at async scrape (/usr/src/app/index.js:174:23)
May 8 09:11:22 PM  
May 8 09:11:22 PM  Node.js v18.16.0

How can I solve this problem ?

Hello there,

I took a look at your issues here and while I couldn’t get the exact same errors you did, I wasn’t able to get Puppeteer working when using the “new headless” option, I have to switch it to use headless: true, when launching Puppeteer.

Give that a shot and see how it goes.

Regards,
Keith

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.