Playwright: [Question] I encounter an error while using playwright

Created on 11 Feb 2020  路  10Comments  路  Source: microsoft/playwright

Hello,

I ran few scripts on my computer with no problem but when I tried them on my server I encountered this problem :

(node:6134) UnhandledPromiseRejectionWarning: Error: Protocol error (Target.getBrowserContexts): Target closed.

It happens when I try to launch the browser.

Full length message :

(node:6134) UnhandledPromiseRejectionWarning: Error: Protocol error (Target.getBrowserContexts): Target closed.
    at /opt/docker-test/master-ci/Ami/tests/playwright/node_modules/playwright-core/lib/chromium/crConnection.js:121:63
    at new Promise (<anonymous>)
    at CRSession.send (/opt/docker-test/master-ci/Ami/tests/playwright/node_modules/playwright-core/lib/chromium/crConnection.js:120:16)
    at Function.connect (/opt/docker-test/master-ci/Ami/tests/playwright/node_modules/playwright-core/lib/chromium/crBrowser.js:48:68)
    at async Chromium.launch (/opt/docker-test/master-ci/Ami/tests/playwright/node_modules/playwright-core/lib/server/chromium.js:45:25)
    at async /opt/docker-test/master-ci/Ami/tests/playwright/test.js:5:25
(node:6134) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:6134) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

My code :

const playwright = require('playwright');

(async () => {
      for (const browserType of ['chromium', 'firefox', 'webkit']) {
              const browser = await playwright[browserType].launch();
              const context = await browser.newContext();
              const page = await context.newPage();
              await page.goto('http://whatsmyuseragent.org/');
              await page.screenshot({ path: `example-${browserType}.png` });
              await browser.close();
            }
})();

Most helpful comment

Another debugging tip is to use launch({dumpio: true}). That prints browser output and helps debugging browser start issues. Could you try that our and send us logs if any? Thanks!

All 10 comments

I assume this is Linux. Chromium recently added libgbm as their dependency. Could you try sudo apt-get install libgbm-dev and tell us if that helped?

Also, https://github.com/microsoft/playwright/blob/master/.travis.yml has dependencies our Travis bots install to run Playwright

Yes exactly, i'm under linux debian but installing libgbm-dev didn't change anything. I also check for missing library but there's no problem with that.

Another debugging tip is to use launch({dumpio: true}). That prints browser output and helps debugging browser start issues. Could you try that our and send us logs if any? Thanks!

Hello, I encounter the same issue trying to run playwright through Node.js in a Docker container.

Adding dumpio give me the following logs:

[0212/132139.073889:FATAL:zygote_host_impl_linux.cc(116)] No usable sandbox! Update your kernel or see https://chromium.googlesource.com/chromium/src/+/master/docs/linux/suid_sandbox_development.md for more information on developing with the SUID sandbox. If you want to live dangerously and need an immediate workaround, you can try using --no-sandbox.,
#0 0x5615bb6028f9 base::debug::CollectStackTrace(),
#1 0x5615bb566ae3 base::debug::StackTrace::StackTrace(),
#2 0x5615bb578865 logging::LogMessage::~LogMessage(),
#3 0x5615bce634ae service_manager::ZygoteHostImpl::Init(),
#4 0x5615bb151627 content::ContentMainRunnerImpl::Initialize(),
#5 0x5615bb19f2fa service_manager::Main(),
#6 0x5615bb14fc41 content::ContentMain(),
#7 0x5615bb19e135 headless::(anonymous namespace)::RunContentMain(),
#8 0x5615bb19dddd headless::HeadlessShellMain(),
#9 0x5615b8c0ca67 ChromeMain,
#10 0x7f9e3dc6309b __libc_start_main,
#11 0x5615b8c0c8aa _start,
,
Received signal 6,
#0 0x5615bb6028f9 base::debug::CollectStackTrace(),
#1 0x5615bb566ae3 base::debug::StackTrace::StackTrace(),
#2 0x5615bb6024a0 base::debug::(anonymous namespace)::StackDumpSignalHandler(),
#3 0x7f9e40121730 (/lib/x86_64-linux-gnu/libpthread-2.28.so+0x1272f),
#4 0x7f9e3dc767bb gsignal,
#5 0x7f9e3dc61535 abort,
#6 0x5615bb6013f5 base::debug::BreakDebugger(),
#7 0x5615bb578d04 logging::LogMessage::~LogMessage(),
#8 0x5615bce634ae service_manager::ZygoteHostImpl::Init(),
#9 0x5615bb151627 content::ContentMainRunnerImpl::Initialize(),
#10 0x5615bb19f2fa service_manager::Main(),
#11 0x5615bb14fc41 content::ContentMain(),
#12 0x5615bb19e135 headless::(anonymous namespace)::RunContentMain(),
#13 0x5615bb19dddd headless::HeadlessShellMain(),
#14 0x5615b8c0ca67 ChromeMain,
#15 0x7f9e3dc6309b __libc_start_main,
#16 0x5615b8c0c8aa _start,
  r8: 0000000000000000  r9: 00007ffe58d8a0f0 r10: 0000000000000008 r11: 0000000000000246,
 r12: 00007ffe58d8b3b8 r13: 00007ffe58d8a390 r14: 00007ffe58d8b3c0 r15: aaaaaaaaaaaaaaaa,
  di: 0000000000000002  si: 00007ffe58d8a0f0  bp: 00007ffe58d8a340  bx: 0000000000000006,
  dx: 0000000000000000  ax: 0000000000000000  cx: 00007f9e3dc767bb  sp: 00007ffe58d8a0f0,
  ip: 00007f9e3dc767bb efl: 0000000000000246 cgf: 002b000000000033 erf: 0000000000000000,
 trp: 0000000000000000 msk: 0000000000000000 cr2: 0000000000000000,
[end of stack trace],
Calling _exit(1). Core file will not be generated.,
ERROR [1581513699763] (41 on 5c7626937691): Protocol error (Target.getBrowserContexts): Target closed.,
    Error: Protocol error (Target.getBrowserContexts): Target closed.,
        at /snapshot/node_modules/playwright-core/lib/chromium/crConnection.js:121:63,
        at new Promise (<anonymous>),
        at CRSession.send (/snapshot/node_modules/playwright-core/lib/chromium/crConnection.js:120:16),
        at Function.connect (/snapshot/node_modules/playwright-core/lib/chromium/crBrowser.js:48:68),
        at Chromium.launch (/snapshot/node_modules/playwright-core/lib/server/chromium.js:45:25),
        at Browser.start (/snapshot/src/browser.ts:13:24),
        at async Promise.all (index 0),
        at main (/snapshot/src/main.ts:16:9),

Ok I get it. It was related to the fact there was no usable sandbox. After set it up it works better. Thanks for the tip of using dumpio. I think you should add it somewhere maybe in troubleshooting (but maybe I missed that)

@brice Can you please details what the sandbox is and how to fix that?

@Vinorcola here is where I found how to fix that : https://github.com/microsoft/playwright/blob/master/docs/troubleshooting.md#setting-up-chrome-linux-sandbox

Thank you!

Looks resolved!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

KevinGrandon picture KevinGrandon  路  4Comments

juliomatcom picture juliomatcom  路  3Comments

etnbrd picture etnbrd  路  4Comments

JoelEinbinder picture JoelEinbinder  路  4Comments

shirshak55 picture shirshak55  路  3Comments