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
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
Saw your is
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.
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.
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:
This issue was not reproducible. Please check that your example runs locally and the following:
puppeteer
andpuppeteer-core
.Bad:
Good:
Error: something went wrong
.Once the above checks are satisfied, please edit your issue with the changes and we will try to reproduce the bug again.
Analyzer run