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

Puppeteer won't launch browsers under WSL2/Ubuntu 22.04.2, but runs just fine under Ubuntu 22.04.2 #5416

Closed
scsmash3r opened this issue Sep 14, 2023 · 2 comments
Labels
bug Something isn't working

Comments

@scsmash3r
Copy link

What version of Bun is running?

1.0.1+31aec4ebe325982fc0ef27498984b0ad9969162b

What platform is your computer?

Linux 5.10.16.3-microsoft-standard-WSL2 x86_64 x86_64, Linux 5.19.0-45-generic x86_64 x86_64

What steps can reproduce the bug?

I have two machines:

  • one with Windows 10, running Linux 5.10.16.3-microsoft-standard-WSL2 x86_64 x86_64 (Ubuntu 22.04.2 under WSL)
  • second with Linux 5.19.0-45-generic x86_64 x86_64 (Ubuntu 22.04.2)

I have the same package.json on both machines:

{
  "name": "bun_puppeteer_tests",
  "module": "index.ts",
  "dependencies": {
    "puppeteer-core": "^21.2.1"
  },
  "devDependencies": {
    "bun-types": "^1.0.1"
  },
  "scripts": {
    "start": "bun run index.ts"
  },
  "type": "module"
}

And the same index.ts contents:

import puppeteer from "puppeteer-core";

await puppeteer.launch({
  headless: false,
  args: ["--no-sandbox", "--disable-dev-shm-usage", "--disable-setuid-sandbox"], // Optional, was trying these
  ignoreDefaultArgs: ["--disable-extensions"], // Optional
  executablePath: "/usr/bin/chromium-browser", // Or any standalone version from https://googlechromelabs.github.io/chrome-for-testing/known-good-versions-with-downloads.json
});

process.exit();

Then do bun run start

What is the expected behavior?

On a Linux 5.19.0-45-generic x86_64 x86_64 machine it works as intended: I see an expected behavior, where browser window opens up.

On a Linux 5.10.16.3-microsoft-standard-WSL2 x86_64 x86_64 I see an errors in output:

What do you see instead?

$ bun run index.ts
[0.02ms] ".env"
809 |       this[kTtyWrite](d, key);
810 |     else
811 |       this[kNormalWrite](d);
812 |   }
813 |
814 |   [kNormalWrite](b) {
                                   ^
TypeError: undefined is not an object
      at node:readline:814:32
      at node:readline:517:40
      at node:stream:1993:76
      at node:stream:2188:80
      at node:stream:1743:322
      at node:readline:535:68
      at new  (node:readline:586:46)
      at node:readline:597:58
263 |                 this.#browserProcess.off('exit', onClose);
264 |                 this.#browserProcess.off('error', onClose);
265 |             };
266 |             function onClose(error) {
267 |                 cleanup();
268 |                 reject(new Error([
                          ^
error: Failed to launch the browser process!


TROUBLESHOOTING: https://pptr.dev/troubleshooting

      at onClose (/home/sc/www/bun_puppeteer_tests/node_modules/@puppeteer/browsers/lib/esm/launch.js:268:23)
      at emit (node:events:122:94)
      at close (node:readline:789:14)
      at node:readline:519:38
      at endReadableNT (node:stream:2387:52)
      at processTicksAndRejections (:1:2602)
error: script "start" exited with code 1 (SIGHUP)

Additional information

I kinda can't wrap my head around regarding how it should work under WSL... Is it intended to work at all? I've also tried to call an .exe version of Chrome standalone, but of course the error was TypeError: Executable not found in $PATH, because I was tying to run a Win excutable while being in Ubuntu's WSL mode.

Does it mean that you by default can not run things like Puppeteer under WSL? Thanks for an answer, will wait for knowledge :)

@scsmash3r scsmash3r added the bug Something isn't working label Sep 14, 2023
@scsmash3r
Copy link
Author

scsmash3r commented Sep 14, 2023

Related: puppeteer/puppeteer#1837

So I've managed to run Puppeteer under WSL in a headless only mode. Steps to make it workable:

wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo apt -y install ./google-chrome-stable_current_amd64.deb

Then this code works:

const browser = await puppeteer.launch({
  headless: true,
  args: ["--no-sandbox", "--disable-dev-shm-usage", "--disable-setuid-sandbox"],
  ignoreDefaultArgs: ["--disable-extensions"],
  executablePath: "/usr/bin/google-chrome",
});
const page = await browser.newPage();
await page.goto("http://example.com");
await page.screenshot({ path: "example.png" });
await browser.close();

If set headless to false, then logically we will get this message:

$ bun run index.ts
[0.02ms] ".env"
263 |                 this.#browserProcess.off('exit', onClose);
264 |                 this.#browserProcess.off('error', onClose);
265 |             };
266 |             function onClose(error) {
267 |                 cleanup();
268 |                 reject(new Error([
                          ^
error: Failed to launch the browser process! undefined
[2736:2736:0915/015528.406203:ERROR:browser_dm_token_storage_linux.cc(100)] Error: /etc/machine-id contains 0 characters (32 were expected).
[2736:2759:0915/015528.408174:ERROR:bus.cc(399)] Failed to connect to the bus: Failed to connect to socket /run/dbus/system_bus_socket: No such file or directory
[2736:2736:0915/015528.411064:ERROR:ozone_platform_x11.cc(240)] Missing X server or $DISPLAY
[2736:2736:0915/015528.411095:ERROR:env.cc(255)] The platform failed to initialize.  Exiting.

... which means we can not display headful state of a browser's window cause... Well, cause we're on Windows mainly, where subsystem is running - so we can not render another OS browser's window :P

So I think I've got to the answer myself, so this will be closed. Hope it will help someone in future.

@scsmash3r scsmash3r changed the title Puppeteer won't launch browsers under WSL/Ubuntu 22.04.2, but runs just fine under Ubuntu 22.04.2 Puppeteer won't launch browsers under WSL2/Ubuntu 22.04.2, but runs just fine under Ubuntu 22.04.2 Sep 14, 2023
@eblake2
Copy link

eblake2 commented Sep 15, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants