Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnhandledPromiseRejectionWarning: Error: Failed to launch browser! #581

Closed
joshsaintjacque opened this issue Jan 23, 2020 · 9 comments
Closed

Comments

@joshsaintjacque
Copy link

joshsaintjacque commented Jan 23, 2020

First of all, thanks for the work on this project! The prospect of a more platform-agnostic alternative to Puppeteer is exciting.

I'm trying to run the example project locally and ran into an issue, hoping maybe someone can point me in the right direction.

The issue

I have a file, test.ts:

const pw = require('playwright');

(async () => {
  const browser = await pw.firefox.launch({ headless: false }); // 'webkit', 'chromium', 'firefox'
  const context = await browser.newContext();
  const page = await context.newPage();

  await page.goto('https://www.example.com/');
  await page.screenshot({ path: 'example.png' });

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

When I run node test.ts I get the following error:

 UnhandledPromiseRejectionWarning: Error: Failed to launch browser!


TROUBLESHOOTING: https://github.com/Microsoft/playwright/blob/master/docs/troubleshooting.md

    at onClose (/mnt/c/Users/joshs/repos/Bullet/api/node_modules/playwright-core/lib/server/processLauncher.js:135:20)
    at Interface.helper_1.helper.addEventListener (/mnt/c/Users/joshs/repos/Bullet/api/node_modules/playwright-core/lib/server/processLauncher.js:128:65)
    at Interface.emit (events.js:202:15)
    at Interface.close (readline.js:395:8)
    at Socket.onend (readline.js:173:10)
    at Socket.emit (events.js:202:15)
    at endReadableNT (_stream_readable.js:1129:12)
    at processTicksAndRejections (internal/process/next_tick.js:76:17)
  -- ASYNC --
    at FFPlaywright.<anonymous> (/mnt/c/Users/joshs/repos/Bullet/api/node_modules/playwright-core/lib/helper.js:54:23)
    at FFPlaywright.launch (/mnt/c/Users/joshs/repos/Bullet/api/node_modules/playwright-core/lib/server/ffPlaywright.js:63:35)
    at FFPlaywright.<anonymous> (/mnt/c/Users/joshs/repos/Bullet/api/node_modules/playwright-core/lib/helper.js:55:31)
    at /mnt/c/Users/joshs/repos/Bullet/api/test.ts:4:36
    at Object.<anonymous> (/mnt/c/Users/joshs/repos/Bullet/api/test.ts:12:3)
    at Module._compile (internal/modules/cjs/loader.js:734:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:745:10)
    at Module.load (internal/modules/cjs/loader.js:626:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:566:12)
    at Function.Module._load (internal/modules/cjs/loader.js:558:3)    
  -- ASYNC --
    at FFPlaywright.<anonymous> (/mnt/c/Users/joshs/repos/Bullet/api/node_modules/playwright-core/lib/helper.js:54:23)
    at /mnt/c/Users/joshs/repos/Bullet/api/test.ts:4:36
    at Object.<anonymous> (/mnt/c/Users/joshs/repos/Bullet/api/test.ts:12:3)
    at Module._compile (internal/modules/cjs/loader.js:734:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:745:10)
    at Module.load (internal/modules/cjs/loader.js:626:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:566:12)
    at Function.Module._load (internal/modules/cjs/loader.js:558:3)    
    at Function.Module.runMain (internal/modules/cjs/loader.js:797:12) 
    at executeUserCode (internal/bootstrap/node.js:526:15)
(node:9422) 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:9422) [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.

What I'm running

I'm running WSL on Windows 10, Node 11.9.0.

What I've tried

I had similar code integrated more deeply into an application I'm working on. I pulled the code out into the simplest reproducible case I could, which is the code above.

I've tried switching between firefox, chromium, and webkit. I've also tried setting headless to false.

Any help or guidance you might be able to offer is appreciated!

@JoelEinbinder
Copy link
Contributor

Thanks for joining us on the bleeding edge!

Did you run both npm install and node test.ts from within WSL? Installing from windows but running from within WSL, or vice versa, would probably cause this error.

Assuming your WSL is Ubuntu based, you probably need to get Chrome's dependencies. It looks like we are missing the list of what those dependencies actually are, but I'd try

sudo apt install \
    gconf-service \
    libasound2 \
    libatk1.0-0 \
    libatk-bridge2.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

You can also launch with the dumpio: true option, to see if there is something helpful being logged by the browser itself.

@joshsaintjacque
Copy link
Author

joshsaintjacque commented Jan 25, 2020

@JoelEinbinder Thanks for your timely response!

I was able to track down the issue. The problem appears to be with Chromium's sandbox. I found some troubleshoot docs from Puppeteer that gave the hint.

I've been unable to get a Chrome sandbox on WSL, but if I disable sandbox (which isn't ideal) it does work:

const browser = await pw.chromium.launch({ args: ['--no-sandbox', '--disable-setuid-sandbox'] });

Edit: I should note that this only works for Chromium. Firefox continues to throw the cryptic UnhandledPromiseRejectionWarning: Error: Failed to launch browser!.

I'm able to get a little more out of Webkit, it throws:

UnhandledPromiseRejectionWarning: Error: Failed to launch browser: Error: spawn /mnt/c/Users/joshs/repos/pw-test/node_modules/playwright-core/.local-webkit/linux-1106/pw_run.sh ENOENT
    at ChildProcess.spawnedProcess.once.error (/mnt/c/Users/joshs/repos/pw-test/node_modules/playwright-core/lib/server/processLauncher.js:49:20)
    at Object.onceWrapper (events.js:285:13)
    at ChildProcess.emit (events.js:197:13)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:252:12)
    at onErrorNT (internal/child_process.js:421:16)
    at processTicksAndRejections (internal/process/next_tick.js:76:17)
  ...

@butlersrepos
Copy link

butlersrepos commented Jan 26, 2020

@JoelEinbinder Those helped me over this hurdle but just wanted to point out that a preliminary

sudo apt-get update

may be needed

@FezVrasta
Copy link

I get the same Error: Chromium revision is not downloaded. Run "npm install" at Chromium.launchBrowserApp (/home/travis/build/popperjs/popper-core/node_modules/playwright-core/lib/server/chromium.js:70:23) on macOS and Travis, the only solution is to delete node_modules and yarn again.

@FezVrasta
Copy link

To add more details, it seems to be a problem with Yarn. npm seems to reliably download the browser binaries every time.

@tyler-graham-ck
Copy link

In the meantime it appears that running node ./node_modules/playwright/install.js before executing your tests will download the binaries if necessary

@pavelfeldman
Copy link
Member

Folding this into #581 and #1085

@pavelfeldman
Copy link
Member

Folding into #1103

@charliedeus
Copy link

Caso ajude alguém, encontrei o apoio necessário em: https://askubuntu.com/questions/1204571/how-to-install-chromium-without-snap

sand4rt pushed a commit to sand4rt/playwright that referenced this issue Dec 21, 2022
Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
Co-authored-by: Max Schmitt <max@schmitt.mx>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants