puppeteer: "Protocol error (Target.createTarget)" when running puppeteer inside AWS lambda container
Steps to reproduce
- Puppeteer version: 5.5.0
- Platform / OS version: Amazon Linux 2
- Node.js version: 12.19
- Lambda memory - 1Gb
What steps will reproduce the problem? Build docker container and deploy it to the AWS Lambda. The following dockerfile runs well in a local docker container and doesn’t run in AWS Lambda env. The code also runs in an EC2 t2.micro env.
FROM public.ecr.aws/lambda/nodejs:12
ENV PUPPETEER_DOWNLOAD_PATH=/var/task/chromium
ENV PUPPETEER_EXECUTABLE_PATH=$PUPPETEER_DOWNLOAD_PATH/linux-818858/chrome-linux/chrome
WORKDIR /var/task
ADD sources /var/task
RUN yum install -y atk java-atk-wrapper at-spi2-atk gtk3 libXt libdrm mesa-libgbm
RUN node ./node_modules/puppeteer/install.js
RUN ldd $PUPPETEER_EXECUTABLE_PATH; exit 0
CMD ["index.handler"]
What is the expected result? Pass all tests:
const puppeteer = require('puppeteer');
let browser = await puppeteer.launch({timeout:60000, headless:true, devtools:true, ignoreHTTPSErrors:true,
acceptInsecureCerts:true, executablePath:process.env.PUPPETEER_EXECUTABLE_PATH, args:[...]});
let page = await browser.newPage();
let response = await page.goto('https://www.microsoft.com', { waitUntil: 'load' });
await page.close();
await browser.close();
What happens instead?
The puppeteer passes the launch and fails at the creation of a new empty page, despite that the ldd $PUPPETEER_EXECUTABLE_PATH
finds all libraries.
puppeteer:launcher Calling /var/task/chromium/linux-818858/chrome-linux/chrome --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=TranslateUI --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --enable-blink-features=IdleDetection --auto-open-devtools-for-tabs --headless --hide-scrollbars --mute-audio about:blank --proxy-server='direct://' --proxy-bypass-list=* --no-sandbox --log-level=3 --no-default-browser-check --disable-site-isolation-trials --no-experiments --ignore-gpu-blocklist --ignore-certificate-errors --ignore-certificate-errors-spki-list --disable-gpu --disable-extensions --disable-default-apps --enable-features=NetworkService --disable-setuid-sandbox --disable-webgl --disable-threaded-animation --disable-threaded-scrolling --disable-in-process-stack-traces --disable-histogram-customizer --disable-gl-extensions --disable-composited-antialiasing --disable-canvas-aa --disable-3d-apis --disable-accelerated-2d-canvas --disable-accelerated-jpeg-decoding --disable-accelerated-mjpeg-decode --disable-app-list-dismiss-on-blur --disable-accelerated-video-decode --remote-debugging-port=0 --user-data-dir=/tmp/puppeteer_dev_chrome_profile-Dbeu48
puppeteer:protocol:SEND ► {"method":"Target.setDiscoverTargets","params":{"discover":true},"id":1}
puppeteer:protocol:RECV ◀ {"method":"Target.targetCreated","params":{"targetInfo":{"targetId":"165C2B4FCBBB01B63251C074627A92E2","type":"page","title":"","url":"about:blank","attached":false,"canAccessOpener":false,"browserContextId":"0D3BA4EED596C6C4B17EB73B41F82957"}}}
puppeteer:protocol:RECV ◀ {"method":"Target.targetCreated","params":{"targetInfo":{"targetId":"58aecf8a-fb9b-4432-9ec3-8c449708f664","type":"browser","title":"","url":"","attached":false,"canAccessOpener":false}}}
puppeteer:protocol:RECV ◀ {"method":"Target.targetCreated","params":{"targetInfo":{"targetId":"e69acc92-f388-4b74-879a-819d331e91b9","type":"browser","title":"","url":"","attached":true,"canAccessOpener":false}}}
puppeteer:protocol:RECV ◀ {"id":1,"result":{}}
INFO: passed puppeteer.launch
puppeteer:protocol:SEND ► {"method":"Target.createTarget","params":{"url":"about:blank"},"id":2}
puppeteer:protocol:RECV ◀ {"method":"Target.targetCrashed","params":{"targetId":"10C805A527EFD2CC1082463E326BA73D","status":"failed to launch","errorCode":1002}}
ERROR: Protocol error (Target.createTarget): Target closed.\n at /var/task/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:71:63\n at new Promise (<anonymous>)\n at Connection.send (/var/task/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:70:16)\n at Browser._createPageInContext (/var/task/node_modules/puppeteer/lib/cjs/puppeteer/common/Browser.js:221:53)\n at BrowserContext.newPage (/var/task/node_modules/puppeteer/lib/cjs/puppeteer/common/Browser.js:500:30)\n at Browser.newPage (/var/task/node_modules/puppeteer/lib/cjs/puppeteer/common/Browser.js:214:37)\n at ...', message: 'Protocol error (Target.createTarget): Target closed.'
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 6
- Comments: 25
Same issue with Puppeteer 8 in a Docker container I can run it without any issues when the Docker host is OSX@Intel but the same code fails when the same docker container is used on OSX@M1 (Apple Silicon)
The test code is the example below. It fails on const page = await browser.newPage(); line
Traceback:
I meet the same problem on AWS lambda, and the flag
--single-process
helps:Not sure if it helps in your case.
https://github.com/microsoft/playwright 😢
Still getting the same error running Puppeteer on Apple Silicon.
@markb-trustifi @jackHedaya have you been able to get puppeteer running in Docker on M1 Silicon? is https://github.com/puppeteer/puppeteer/pull/7546 related?
Getting the same exact issue with my lambda container function.
Protocol error (Target.setDiscoverTargets): Target closed. at /var/task/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:71:63 at new Promise (<anonymous>) at Connection.send (/var/task/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:70:16) at Function.create (/var/task/node_modules/puppeteer/lib/cjs/puppeteer/common/Browser.js:117:26) at ChromeLauncher.launch (/var/task/node_modules/puppeteer/lib/cjs/puppeteer/node/Launcher.js:103:56) at processTicksAndRejections (internal/process/task_queues.js:95:5) at async PuppeteerExtra.launch (/var/task/node_modules/puppeteer-extra/dist/index.cjs.js:129:25) at async launchBrowser (/var/task/puppeteer/utils/index.js:7:18) at async main (/var/task/index.js:19:13) at async retryWithTimeOut (/var/task/utils/retry.js:17:10) at async Runtime.exports.lambdaHandler [as handler] (/var/task/index.js:110:3
by the way, when I run locally using Lambda Runtime Interface Emulator everything works smoothly.
Same issue with Alpine running in AWS Fargate. Only --single-process fixes it. This problem doesn’t happen on EC2, Cloud9, or even containers built and run on Apple M1.
I’m using Node 20 with Puppeteer version 21 but also saw it on all versions of Puppeteer 20. Dockerfile and package.json are here.
Worked like a charm! Thanks a lot - life saviour after many days banging my head against the wall