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 (Runtime.callFunctionOn): Target closed." inside Docker container.

See original GitHub issue

Steps to reproduce

Tell us about your environment:

  • Puppeteer version:1.9.0
  • Platform / OS version: docker image - node:8.11.3
  • URLs (if applicable):
  • Node.js version:8.11.3

What steps will reproduce the problem?

Please include code that reproduces the issue.

1.Build docker image with following:

FROM node:8.11.3

RUN apt-get update && \
    apt-get -y install xvfb gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 \
      libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 \
      libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 \
      libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 \
      libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget && \
rm -rf /var/lib/apt/lists/*

RUN mkdir -p /usr/src/app
WORKDIR /usr/src/app
COPY package.json /usr/src/app/
RUN npm install --unsafe-perm=true --allow-root

COPY . /usr/src/app
CMD [ "npm", "test", "example2.test.js"]
  1. My example2.test.js to test puppeteer in container:

let browser
let page

test('Test', async() => {
  browser = await puppeteer.launch({
    args: [
      // Required for Docker version of Puppeteer
      '--no-sandbox',
      '--disable-setuid-sandbox',
      // This will write shared memory files into /tmp instead of /dev/shm,
      // because Docker’s default for /dev/shm is 64MB
      '--disable-dev-shm-usage'
    ]
  })

  const browserVersion = await browser.version()
  console.log(`Started ${browserVersion}`)
  
  page = await browser.newPage()
  const response = await page.goto('http://google.com/')
  let searchform = await page.waitForSelector('#searchform');

  await searchform.click();
  await page.screenshot({path: './screenshot.png', fullPage: true});
  
  await page.close()
  await browser.close()
    
})
  1. Run the container and the test failed when click a element:
> puppet@1.0.0 test /usr/src/app
> jest "example2.test.js"

  console.log example2.test.js:20
    Started HeadlessChrome/73.0.3679.0

FAIL ./example2.test.js (8.664s)
  ✕ Test (7844ms)

  ● Test

    Protocol error (Runtime.callFunctionOn): Target closed.

      24 |   let searchform = await page.waitForSelector('#searchform');
      25 |
    > 26 |   await searchform.click();
         |                    ^
      27 |   await page.screenshot({path: './screenshot.png', fullPage: true});
      28 |
      29 |   await page.close()

      at Promise (node_modules/puppeteer/lib/Connection.js:183:56)
      at CDPSession.send (node_modules/puppeteer/lib/Connection.js:182:12)
      at ExecutionContext.evaluateHandle (node_modules/puppeteer/lib/ExecutionContext.js:106:44)
      at ExecutionContext.<anonymous> (node_modules/puppeteer/lib/helper.js:109:23)
      at ExecutionContext.evaluate (node_modules/puppeteer/lib/ExecutionContext.js:48:31)
      at ExecutionContext.<anonymous> (node_modules/puppeteer/lib/helper.js:109:23)
      at ElementHandle._scrollIntoViewIfNeeded (node_modules/puppeteer/lib/JSHandle.js:163:49)
      at ElementHandle.click (node_modules/puppeteer/lib/JSHandle.js:247:16)
      at ElementHandle.<anonymous> (node_modules/puppeteer/lib/helper.js:109:23)
      at Object.click (example2.test.js:26:20)

What is the expected result? The test should pass. The same code run in Ubuntu 16 outside the container without any problem.

What happens instead? Exception thorws: Protocol error (Runtime.callFunctionOn): Target closed.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:8
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
haikyuucommented, Mar 15, 2019

@mustafah15 it works using puppeteer@1.11.0

0reactions
haikyuucommented, Mar 18, 2019

Thank you @aslushnikov 👍

Read more comments on GitHub >

github_iconTop Results From Across the Web

Protocol error (Runtime.callFunctionOn): Session closed ...
This causes some pages to silently crash 'Page has been closed. ... problem by moving the code from a docker container to a...
Read more >
Protocol error (Page.printToPDF): Target closed. - jsreport forum
Hi, just refining the question here. If I run the template in version 2.5.0 i get this error: Protocol error (Runtime.callFunctionOn): Target ......
Read more >
qawolf/community - Gitter
Is it normal to have "error: retryExecutionError: will not retry error >3x: "Protocol error (Runtime.callFunctionOn): Target closed." in the QA Wolf console ...
Read more >
Error - Target closed - Checkly
Possible causes. Obvious possible cause: the browser, context or tab is being closed at the wrong time in the script. Not-so-obvious ...
Read more >
Discussion of How to use Puppeteer inside a Docker container
setAutoAttach): Target closed." 2022-09-15T05:46:28.039Z a251301b-87b7-4e34-bf7c-c1d0a42ae6f5 ERROR ProtocolError: Protocol error ( ...
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