question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

"Protocol error (Target.createTarget)" when running puppeteer inside AWS lambda container

See original GitHub issue

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.'

Issue Analytics

  • State:open
  • Created 3 years ago
  • Reactions:5
  • Comments:20

github_iconTop GitHub Comments

17reactions
narocommented, Mar 20, 2021

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

const puppeteer = require('puppeteer');

(async () => {
  const browser = await puppeteer.launch({args: ['--no-sandbox', '--disable-setuid-sandbox']});
  const page = await browser.newPage();
  await page.goto('https://example.com');
  await page.screenshot({ path: 'example.png' });

  await browser.close();
})();

Traceback:

/usr/local/puppeteer-pdf/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:71
            this._callbacks.set(id, { resolve, reject, error: new Error(), method });
                                                              ^

Error: Protocol error (Target.createTarget): Target closed.
    at /usr/local/puppeteer-pdf/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:71:63
    at new Promise (<anonymous>)
    at Connection.send (/usr/local/puppeteer-pdf/node_modules/puppeteer/lib/cjs/puppeteer/common/Connection.js:70:16)
    at Browser._createPageInContext (/usr/local/puppeteer-pdf/node_modules/puppeteer/lib/cjs/puppeteer/common/Browser.js:242:53)
    at BrowserContext.newPage (/usr/local/puppeteer-pdf/node_modules/puppeteer/lib/cjs/puppeteer/common/Browser.js:500:30)
    at Browser.newPage (/usr/local/puppeteer-pdf/node_modules/puppeteer/lib/cjs/puppeteer/common/Browser.js:235:37)
    at /usr/local/puppeteer-pdf/example.js:5:30
    at processTicksAndRejections (node:internal/process/task_queues:94:5)
3reactions
lucklovecommented, Jul 2, 2022

I meet the same problem on AWS lambda, and the flag --single-process helps:

        const browser = await puppeteer.launch({
            headless: true,
            args: ['--use-gl=egl', '--no-sandbox', '--single-process'],
        });

Not sure if it helps in your case.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to use Puppeteer inside a Docker container
Introduction Puppeteer is a Node.js library which provides a high-level API to control... ... and i get this error "Protocol error (Target.
Read more >
Protocol error (Page.captureScreenshot): Target closed ...
js makes high quality screenshots on the host OS, but fails in a container. Is there any magic parameter to run it in...
Read more >
Puppeteer on AWS Lambda
There are a few challenges when it comes to getting Puppeteer to work properly on AWS Lambda, and we'll address all of them...
Read more >
headless chrome & aws lambda
Has anyone tried to run headless chrome inside aws lambda function? ... That said, Lambda can start Container Service tasks, which means you ......
Read more >
try - Mercurial - Mozilla
waitForSelector should run in specified frame (waittask.spec.ts)": ... +- [Puppeteer on AWS Lambda](https://github.com/jay-deshmukh/headless-chrome-with- ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found