On Ubuntu 16.04.3 LTS via WSL (Linux pc-name 4.4.0-43-Microsoft #1-Microsoft Wed Dec 31 14:42:53 PST 2014 x86_64 x86_64 x86_64 GNU/Linux).
Gives this error:
ERROR { Error: kill ESRCH
at Object._errnoException (util.js:1024:11)
at process.kill (internal/process.js:183:18)
at forceKillChrome (/mnt/c/Users/me/code/node_modules/puppeteer/lib/Launcher.js:169:19)
at Function.launch (/mnt/c/Users/me/code/node_modules/puppeteer/lib/Launcher.js:144:7)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7) code: 'ESRCH', errno: 'ESRCH', syscall: 'kill' }
ERROR { Error: kill ESRCH
at Object._errnoException (util.js:1024:11)
at process.kill (internal/process.js:183:18)
at forceKillChrome (/mnt/c/Users/me/code/node_modules/puppeteer/lib/Launcher.js:169:19)
at Function.launch (/mnt/c/Users/me/code/node_modules/puppeteer/lib/Launcher.js:144:7)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7) code: 'ESRCH', errno: 'ESRCH', syscall: 'kill' }
Have tried:
sudo apt install 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
... which doesn't help.
Only other mention I can find of Puppeteer on WSL is https://github.com/GoogleChrome/puppeteer/issues/290#issuecomment-322964612.
I had this feeling that it won't work under WSL out of the box, so I didn't even attempt to do so. I just used VirtualBox. It would be awesome to make it run though.
I'm seeing this as well on every WSL installation I check, here's hoping Windows 10 1803 will solve it next month.
Would like to see pupeteer working on WSL. I am using Ubuntu in WSL and have this issue too.
I'm on WSL and I have the same issue.
Has anyone tried this on the newest insider builds? Something close to the upcoming Spring Creator's Update?
Just tested in 1803, seems to work on this build (only tested on project though).
Testing on another machine, I'm getting an "unhandled promise rejection" error. Testing some more, will report back... Using this test script I wrote.
(node:2114) UnhandledPromiseRejectionWarning: Error: kill ESRCH
at Object._errnoException (util.js:1022:11)
at process.kill (internal/process.js:183:18)
at forceKillChrome (/mnt/c/Users/Jacob/Repositories/critical-test/node_modules/puppeteer/lib/Launcher.js:169:1
9)
at Function.launch (/mnt/c/Users/Jacob/Repositories/critical-test/node_modules/puppeteer/lib/Launcher.js:144:7
)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
(node:2114) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwin
g inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch()
. (rejection id: 1)
(node:2114) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise reje
ctions that are not handled will terminate the Node.js process with a non-zero exit code.
(node:2114) UnhandledPromiseRejectionWarning: Error: kill ESRCH
at Object._errnoException (util.js:1022:11)
at process.kill (internal/process.js:183:18)
at forceKillChrome (/mnt/c/Users/Jacob/Repositories/critical-test/node_modules/puppeteer/lib/Launcher.js:169:1
9)
at Function.launch (/mnt/c/Users/Jacob/Repositories/critical-test/node_modules/puppeteer/lib/Launcher.js:144:7
)
at <anonymous>
at process._tickCallback (internal/process/next_tick.js:188:7)
(node:2114) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwin
g inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch()
. (rejection id: 2)
Testing on my original machine, getting the exact same error. This worked once, no clue why it wouldn't be working now. Scanning through the code where the error is occurring, it seems that the problem is something to do with the forceKillChrome() function, possibly related to how it checks what plat form it's being run on.
This is the line that's causing the error.
Things I've found while debugging:
console.log(process.platform) returns linuxconsole.log(typeof process.kill) returns functionconsole.log(chromeProcess.pid) returns the process numberAll that seems fine to me, I can't tell what would be causing the issue.
Some Googling, it sounds like it may be an issue with the wrong pid being returned on WSL. -- see https://github.com/Tyriar/node-pty/issues/45
I just installed Chromium via sudo apt-get install chromium-browser (via https://github.com/GoogleChrome/puppeteer/issues/1700#issuecomment-369807464), and it started working with my basic test script, but still doesn't work with my gulpfile for some reason, not sure what the difference is.
I installed Chromium via the same command and was not able to get a simple script to work; the following is the error message:
(node:761) UnhandledPromiseRejectionWarning: Error: Failed to launch chrome!
TROUBLESHOOTING: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md
at onClose (/mnt/c/Users/Kimeiga/Google Drive/Projects/web/puppeteer test/node_modules/puppeteer/lib/Launcher.js:255:14)
at ChildProcess.helper.addEventListener (/mnt/c/Users/Kimeiga/Google Drive/Projects/web/puppeteer test/node_modules/puppeteer/lib/Launcher.js:245:60)
at ChildProcess.emit (events.js:182:13)
at Process.ChildProcess._handle.onexit (internal/child_process.js:235:12)
(node:761) 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:761) [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.
The above was run through bash; I also ran it through PowerShell and received the following:
(node:6164) UnhandledPromiseRejectionWarning: AssertionError [ERR_ASSERTION]: Chromium revision is not downloaded. Run "npm install" or "yarn install"
at Console.assert (console.js:194:23)
at Function.launch (C:\Users\Kimeiga\Google Drive\Projects\web\puppeteer test\node_modules\puppeteer\lib\Launcher.js:100:15)
at <anonymous>
(node:6164) 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:6164) [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.
Running npm install and yarn install didn't help
The following works for me in latest WSL:
npm install puppeteer
sudo apt-get install chromium-browser
const puppeteer = require('puppeteer');
(async() => {
const browser = await puppeteer.launch({executablePath: '/usr/bin/chromium-browser'});
console.log(await browser.version());
const page = await browser.newPage();
await page.goto('https://google.com');
await page.screenshot({path: 'google.png'});
await browser.close();
})();
If anyone's having trouble, as an alternative option, letting it control Windows Chrome/Chromium seems to work fine (for me at least).
I added my Chrome directory to my PATH on the Windows side, it automatically gets translated/appended to PATH on the WSL side, so after that it's literally just:
const browser = await puppeteer.launch({ executablePath: 'chrome.exe' })
And this way you actually have the option of running it non-headless without having to run a window server, install a desktop environment, etc.
Obviously try and make sure you're using a compatible version.
Quick tip, if you run node --experimental-repl-await (Node 10) you can play around in a Node REPL with top level await (no need for a wrapping function), which makes testing this stuff a whole lot easier/more fun.
Edit: there is at least one caveat with this method, see below.
I have added Windows Chrome to my Path, and set executablePath when I launch(). This doesn't raise an exception anymore. However, after calling newPage on the browser the script stalls and never finishes. I'm not sure if Chrome is supposed to launch, but it doesn't. I'll try to debug it and see where it's hanging. Any ideas?
I was running into the same problem with newPage() in headless mode (but not with headless: false). What seems to fix it for me is setting userDataDir in the launch options. Be aware that this will be a Windows path, not a WSL one, because it gets passed to the browser as an argument. If you don't specify this, by default it tries to create a profile directory at /tmp/puppeteer_dev_profile-<randomized string>, which actually results in it being created in C:\tmp\... - maybe that causes an issue because of permissions or something.
The other issue I ran into is that this directory never gets cleaned up like it should when you close the browser, whether you manually specify userDataDir or not (you should check out C:\tmp as already mentioned because there's likely a whole bunch of useless folders in there). You can use a module like rimraf or fs-extra to remove it manually instead.
Example:
const puppeteer = require('puppeteer');
const rimraf = require('rimraf');
const USER_DATA_DIR = 'D:\\temp\\puppeteer_user_data';
const USER_DATA_DIR_WSL = '/mnt/d/temp/puppeteer_user_data';
(async () => {
const browser = await puppeteer.launch({
executablePath: 'chrome.exe',
userDataDir: USER_DATA_DIR
});
...
await browser.close();
})().finally(() => rimraf(USER_DATA_DIR_WSL));
Maybe this is something that can be fixed in the library with a little WSL detection magic.
const browser = await puppeteer.launch({
args: ['--no-sandbox', '--disable-setuid-sandbox']
});
tranxuanloc comment allowed me to run pupeteer 1.11.0 with WSL in headless mode. The newer versions of pupeteer was causing issues for me.
I also tried all of the solutions here. Nothing worked except disabling the sandbox unfortunately.
Got it working pretty nicely on WSL2 after installing the libs, also works in headful mode through an x server (been using VcXsrv).
cant wait to get wsl2 ...
So I tried running it on wsl 2 and it just wouldn't work. Then I ran sudo apt install chromium-browser to install chromium. After that was done, in my project directory, I ran npm i puppeteer-core. After that, I included puppeteer-core in my app.js and I ran which chromium-browser to find the location of the browser itself. Once I had that, I added the path to it in the puppeteer.launch function as the executablePath argument. So my code now looks like this:
const puppeteer = require("puppeteer-core");
(async () => {
const browser = await puppeteer.launch({
executablePath: "/usr/bin/chromium-browser"
});
const page = await browser.newPage();
await page.goto("https://www.example.com");
await page.screenshot({ path: "example.png" });
await browser.close();
})();
And it works flawlessly! I don't know if it works on wsl 1, I haven't tried. Someone try it and let me know.
I hope this helps you guys!
It just hangs for me if I try setting "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe" as the executablePath unless I also add userDataDir. So, final solution to get it to run on both Windows and WSL is:
#!/usr/bin/env node
const puppeteer = require('puppeteer-core');
const rimraf = require('del');
const PATHS = {
win32: {
executablePath: "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe",
userDataDir: 'C:\\Users\\<USERNAME>\\AppData\\Local\\Temp\\puppeteer_user_data',
},
linux: {
executablePath: "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe",
userDataDir: '/mnt/c/Users/<USERNAME>/AppData/Local/Temp/puppeteer_user_data',
},
}
async function main() {
const browser = await puppeteer.launch({
executablePath: PATHS[process.platform].executablePath,
userDataDir: PATHS.win32.userDataDir,
headless: false,
});
const page = await browser.newPage();
await page.goto('https://example.org');
await page.screenshot({path: `${__dirname}/screenshots/login.png`});
await browser.close();
}
main().finally(async () => {
await rimraf(PATHS[process.platform].userDataDir, {force: true})
}).catch(err => {
console.error(err);
process.exit(1);
});
I also couldn't get chromium-browser to work, but if you want to give it a whirl, here's some copy-pasta:
sudo add-apt-repository ppa:chromium-team/stable
sudo apt-get update
sudo apt install chromium-browser
yarn add puppeteer-core --dev
which chromium-browser
const browser = await puppeteer.launch({ args: ['--no-sandbox', '--disable-setuid-sandbox'] });
I tried and it works...
This works for me:
const browser = await puppeteer.launch({
args: [
'--disable-gpu',
'--disable-dev-shm-usage',
'--disable-setuid-sandbox',
'--no-first-run',
'--no-sandbox',
'--no-zygote',
'--single-process',
]
})
I couldn't get native puppeteer to work (on WSL1 and Ubuntu), but I was able to get my code to work with Windows Chrome using the following:
export PATH=/mnt/c/Program\ Files\ \(x86\)/Google/Chrome/Application:$PATH
.
const browser = await puppeteer.launch({ executablePath: 'chrome.exe', headless: false });
Thanks all
['--no-sandbox', '--disable-setuid-sandbox']
was our winner
beforeEach(async () => {
browser = await puppeteer.launch({
headless: true,
ignoreDefaultArgs: ['--disable-extensions'],
args: [
// '--disable-gpu',
// '--disable-dev-shm-usage',
// '--disable-setuid-sandbox', //default
// '--no-first-run',
'--no-sandbox', // default
// '--no-zygote',
'--single-process',
]
});
page = await browser.newPage();
await page.setViewport({ width: 900, height: 600 });
await page.goto('http://localhost:3000/');
await page.waitForSelector(pageObjects.navFactory);
});
Just adding my experience as it seems to differ from others here. On Windows 10.0.18362, Ubuntu 18.04, puppeteer 2.0.0.
The error I get after a wait is:
(node:2369) UnhandledPromiseRejectionWarning: TimeoutError: Timed out after 30000 ms while trying to connect to Chrome! The only Chrome revision guaranteed to work is r706915
at Timeout.onTimeout (/mnt/c/Users/tarek/Code/picogl.js/node_modules/puppeteer/lib/Launcher.js:359:14)
at ontimeout (timers.js:424:11)
at tryOnTimeout (timers.js:288:5)
at listOnTimeout (timers.js:251:5)
at Timer.processTimers (timers.js:211:10)
I'm using the locally-installed chromium that comes with puppeteer, so the the version mismatch doesn't make much sense.
So my experience on this one was surprisingly easy, and it makes me think it might be fixed.
I'm on windows 10, regular WSL.
At first, puppeteer was failing because it was missing a library in the nodeModules folder in windows (where the code lives). I assumed that this had to do with what I saw here, and tried to install chromium with WSL, and do the various workarounds here.
After all of that not working for some time, I decided to just try it again with the default executablePath that's out of the box with puppeteer (definition of insanity is...?) - and it worked perfectly. (just with the --no-sandbox argument, since I was running the browser as root).
So, the lesson is (from my experience) - it works out of the box as you'd expect ASSUMING that you run apt install chromium-browser in WSL first, and use the --no-sandbox argument in addition.
Hi,
I made a really simple package running puppeteer with the required settings in regards to the environment:
https://gitlab.com/pushrocks/smartpuppeteer
It also works in wsl 1.
As I took a while to find the instructions, I am posting here:
If you want to use Puppetter on WSL2 with {headless: false} (so, to open the Chrome natively), the easiest way is to install VcXsrc on your Windows.
Step by step you can find it here (just ignore the part on what he says about Cypress)
For people coming to this issue in 2020, the "Timed out after 30000" message doesn't actually tell you what the problem is, it just means that chrome isn't launching successfully. To debug that, you can grab the command-line parameters puppeteer is using to launch chrome and then run that yourself manually. My issue was that I had accidentally defined the DISPLAY environment variable, in WSL2 and chrome was hanging trying to connect to X.
It would be great if puppeteer could scoop up the chrome output on timeout and display it to aide with debugging.
I am new to puppeteer and node and can not understand the issue.
Please help.
WSL: Ubuntu 18.04
puppeteer: 2.1.0
script:
Issue puppeteer.docx
@nehamjadhav have you tried running it without sandbox?
puppeteer.launch({ args : ['--no-sandbox'] })
@nehamjadhav have you tried running it without sandbox?
puppeteer.launch({ args : ['--no-sandbox'] })
Yes.
My script:
const puppeteer = require('puppeteer');
(async() => {
const browser = await puppeteer.launch({executablePath: '/usr/bin/chromium-browser',
userDataDir:'/usr/bin/tmp/puppeteer',
args: ['--no-sandbox']});
console.log(await browser.version());
console.log(browser.isConnected());
const page = await browser.newPage();
console.log(browser.isConnected());
await page.goto('http://www.google.com');
console.log(browser.isConnected());
//await page.screenshot({path: 'google.png'});
await browser.close();
})();
Output:
HeadlessChrome/79.0.3945.79
true
true
(node:15217) UnhandledPromiseRejectionWarning: Error: Navigation failed because browser has disconnected!
at CDPSession.LifecycleWatcher._eventListeners.helper.addEventListener (/mnt/c/xampp/htdocs/pdf2charinfo/node_modules/puppeteer/lib/LifecycleWatcher.js:46:107)
at CDPSession.emit (events.js:198:13)
at CDPSession._onClosed (/mnt/c/xampp/htdocs/pdf2charinfo/node_modules/puppeteer/lib/Connection.js:215:10)
at Connection._onClose (/mnt/c/xampp/htdocs/pdf2charinfo/node_modules/puppeteer/lib/Connection.js:138:15)
at WebSocketTransport._ws.addEventListener.event (/mnt/c/xampp/htdocs/pdf2charinfo/node_modules/puppeteer/lib/WebSocketTransport.js:48:22)
at WebSocket.onClose (/mnt/c/xampp/htdocs/pdf2charinfo/node_modules/ws/lib/event-target.js:124:16)
at WebSocket.emit (events.js:198:13)
at WebSocket.emitClose (/mnt/c/xampp/htdocs/pdf2charinfo/node_modules/ws/lib/websocket.js:191:10)
at Socket.socketOnClose (/mnt/c/xampp/htdocs/pdf2charinfo/node_modules/ws/lib/websocket.js:850:15)
at Socket.emit (events.js:198:13)
try await page.goto('http://google.com', { waitUntil : 'networkidle0' })
My current configuration for a working project:
[
"--disable-gpu",
"--renderer",
"--no-sandbox",
"--no-service-autorun",
"--no-experiments",
"--no-default-browser-check",
"--disable-dev-shm-usage",
"--disable-setuid-sandbox",
"--no-first-run",
"--no-zygote",
"--single-process",
"--disable-extensions"
]
It was mostly selective trail and error until I got this one working.
I fixed the error when using the executablePath with Windows's Chrome by simply creating a directory tmp at C:\tmp.
Thanks to @mnpenner, your code block fixed it for me. However, I am getting an error:
[Error: EACCES: permission denied, unlink '/mnt/c/Users/<USERNAME>/AppData/Local/Temp/puppeteer_user_data/lockfile'] {
errno: -13,
code: 'EACCES',
syscall: 'unlink',
path: '/mnt/c/Users/<USERNAME>/AppData/Local/Temp/puppeteer_user_data/lockfile'
}
Depending on whether or not I comment out the page.goto line or the page.screenshot line, the path changes to .../puppeteer_user_data/Default/Cookies and .../puppeteer_user_data/Default/Cookies-journal.
It doesn't seem to be affecting the launching of chrome as far as I can tell.
I evaluated Windows linux Subsystem for Frontend Development and, 5/2020, it appears far from ready. Back to OSX! there's still work to do guys, good luck!
Using chromium-browser installed via apt as the the executable the only flags I needed (after much trial and error) were --disable-gpu and --single-process.
I was unable to install chromium-browser through apt in the 20.20 version of Ubuntu WSL because it was "Unable to reach the snap store".
Works great after upgrading to WSL2.
For me this was by far the best solution when comparing to the other two solutions:
--disable-setuid-sandbox and --no-sandbox (kinda unsafe if you don't trust the places you will browse with puppeteer)For upgrading to WSL2
wsl --list --verbose or wsl -l -v in short to see the name of my distro, and then wsl --set-version <distroname> 2. This starts the conversion process which took me 3-4 hours, even though it says "this may take a few minutes" so if you wanna be safe I would do it while you're sleeping ;). It will say something along the lines of "conversion has completed" so watch for that to confirm you upgraded. Otherwise, something is probably wrong.I hope it helps someone out there and maybe the issue can be closed when WSL2 is more "stable"
Works great after upgrading to WSL2.
For me this was by far the best solution when comparing to the other two solutions:
- linking to windows host chrome executable
--disable-setuid-sandboxand--no-sandbox(kinda unsafe if you don't trust the places you will browse with puppeteer)For upgrading to WSL2
- I had to download the kernel update here https://docs.microsoft.com/en-us/windows/wsl/wsl2-kernel
- Ensure you have hardware virtualization turned on, the command prompt isn't that descriptive about it when you don't.
- Follow https://docs.microsoft.com/en-us/windows/wsl/install-win10#update-to-wsl-2
- Also, for me doing the set-default-version wasn't enough, to convert from wsl1 to wsl2 I had to run:
wsl --list --verboseorwsl -l -vin short to see the name of my distro, and thenwsl --set-version <distroname> 2. This starts the conversion process which took me 3-4 hours, even though it says "this may take a few minutes" so if you wanna be safe I would do it while you're sleeping ;). It will say something along the lines of "conversion has completed" so watch for that to confirm you upgraded. Otherwise, something is probably wrong.I hope it helps someone out there and maybe the issue can be closed when WSL2 is more "stable"
i have this error after update to wsl2
I'm using WSL2 on Windows build 19041 with Ubuntu 20.
I didn't want to install an X server, and wanted native performance / display scaling / etc., so I tried very hard to get calling the native Windows Chrome executable via executablePath to work. It was a huge pain to try to get it to be happy with any userDataDir that was passed. It kept complaining that it couldn't access or write to it, whether it was a path inside or outside WSL. Eventually, I did get it partially working to start up (with a variation of a 777'ed /tmp/.. or C:\tmp\.. by the end I think, but I didn't chronicle that part), only to be faced with a cryptic [object Object] error with exit code 1, that I assume was thrown from some part of Puppeteer itself not enjoying an out-of-sync Chrome's automation protocols. I don't know if that was actually the issue or not, but for posterity, my native Chrome version as of this writing is 83.0.4103.97, and puppeteer version 3.3.0.
Finally I gave up. As @bruno222 suggested earlier in this issue, you can just install an X server and then let Puppeteer's packaged Chromium have a display to make a visible window in. To do this, install https://sourceforge.net/projects/vcxsrv/ and follow the instructions to start it at https://nickymeuleman.netlify.app/blog/gui-on-wsl2-cypress (TL;DR - install normally, and on startup select 'Multiple windows', 'Start no client', and check on 'Disable access control'). Then add this to your .bashrc / .zshrc, and source it or restart:
# Set up DISPLAY on the current container (to connect to VcXsrv)
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}'):0.0
I also installed these packages inside of Ubuntu (pipe them into apt-get install), a step which might be required for you too if you didn't install chromium-browser or any other GUI apps in it yet. I didn't narrow down which are actually required, but certainly the X libs at least:
fonts-liberation
gconf-service
libappindicator1
libasound2
libatk-bridge2.0-0
libatk1.0-0
libc6
libcairo2
libcups2
libdbus-1-3
libexpat1
libfontconfig1
libgbm1
libgcc1
libgconf-2-4
libgdk-pixbuf2.0-0
libglib2.0-0
libgtk-3-0
libnspr4
libnss3
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
lsb-release
wget
xdg-utils
If all went well, you should see Chromium pop up next time you start puppeteer in headless: false
WOW that was a struggle
As @jrajav and @bruno222 has suggested, follow
https://nickymeuleman.netlify.app/blog/gui-on-wsl2-cypress
I'm not sure if this affected anything, but I also had to do
sudo /etc/init.d/dbus start &> /dev/null
and sudo visudo -f /etc/sudoers.d/dbus to have <your_username> ALL = (root) NOPASSWD: /etc/init.d/dbus in the file.
Finally make sure you do the disable access control...

I've got it working on WSL2 with Ubuntu 20.04 using chromium:
1 - Follow the instructions here to install chromium from Debian Buster's repos. For the /etc/apt/sources.list.d/debian.list file, use the following:
deb http://ftp.debian.org/debian buster main
deb http://ftp.debian.org/debian buster-updates main
deb http://security.debian.org/debian-security buster/updates main contrib non-free
And for /etc/apt/preferences.d/chromium.pref:
# Note: 2 blank lines are required between entries
Package: *
Pin: release a=focal
Pin-Priority: 500
Package: *
Pin: origin "ftp.debian.org"
Pin-Priority: 300
# Pattern includes 'chromium', 'chromium-browser' and similarly
# named dependencies:
Package: chromium*
Pin: origin "ftp.debian.org"
Pin-Priority: 700
2 - Follow @junminstorage 's instructions above: https://github.com/puppeteer/puppeteer/issues/1837#issuecomment-405047723, replacing
const browser = await puppeteer.launch({executablePath: '/usr/bin/chromium-browser'}); with const browser = await puppeteer.launch({executablePath: '/usr/bin/chromium'});
Thanks to all in this thread for hits!
I managed to run headless: false with X-server. It does not require for any extra args and runs chromium embedded to puppeteer package. I means I don't need any extra code to handle WSL2, I can run same script that work in windows and desktop ubuntu.
Here is a step by step from clean ubuntu in wsl2 to opened chromium window:
sudo apt updatesudo apt upgradesudo visudo -f /etc/sudoers.d/dbus - A Nano editor will launch<your_username> is replaced by _your username_<your_username> ALL = (root) NOPASSWD: /etc/init.d/dbusctrl+X to close, and agree to save changes.bashrc (or .zshrc if you are using ZSH)
# set DISPLAY variable to the IP automatically assigned to WSL2
export DISPLAY=$(cat /etc/resolv.conf | grep nameserver | awk '{print $2; exit;}'):0.0
sudo /etc/init.d/dbus start &> /dev/null
source ~/.bashrc - apply changessudo apt-get install for all packages from here https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md#chrome-headless-doesnt-launch-on-unixmkdir pup-wsl2 && cd pup-wsl2npm init -ynpm install puppeteernode --experimental-repl-awaitconst b = await require('puppeteer').launch({ headless: false }); (in REPL) Now you have opened chromium window. You can continue play with it in REPL (const p = await b.newPage(); await p.goto('https://example.com');), or close REPL and run you scripts.
"--disable-gpu",
"--disable-setuid-sandbox",
"--no-sandbox",
"--single-process"
was the working combination for me with WSL1 on Windows 10 - 2004.
I'm using this to run pa11y
Most helpful comment
This works for me: