-
Notifications
You must be signed in to change notification settings - Fork 9.1k
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 doesn't run under WSL (Windows subsystem for Linux) #1837
Comments
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.
|
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 This is the line that's causing the error. Things I've found while debugging:
All 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 microsoft/node-pty#45 |
I just installed Chromium via |
I installed Chromium via the same command and was not able to get a simple script to work; the following is the error message:
The above was run through bash; I also ran it through PowerShell and received the following:
Running npm install and yarn install didn't help |
The following works for me in latest WSL:
|
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 Edit: there is at least one caveat with this method, see below. |
I have added Windows Chrome to my Path, and set |
I was running into the same problem with 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 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
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. |
It just hangs for me if I try setting #!/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
|
I tried and it works... |
This works for me:
|
It was mentioned in different ways before by a few users, but somehow got lost in the thread. This is what worked for me on WSL2 running an Ubuntu 20.04:
|
I confirm that the above answer is the solution. It works for me. |
For anyone else who followed steps from #1837 (comment) - in my company we use Cisco AnyConnect VPN. This borked the network connection of WSL, so I followed this: https://gist.github.com/machuu/7663aa653828d81efbc2aaad6e3b1431
basically you want this to be host ip assigned by the VPN, so double check if those are the same and if not tweak i.e. tail param |
Likewise |
I followed these steps, but only needed to use |
The quickest solution for me was to install the packages listed below. After that puppeteer runs out of the box, without additional launch options for the browser. |
Thank you very much! This worked for me! |
We're marking this issue as unconfirmed because it has not had recent activity and we weren't able to confirm it yet. It will be closed if no further activity occurs within the next 30 days. |
I'm using WSL2 and this is what worked for me!
If you are able to execute |
We probably need to include the info into the troubleshooting guide. Happy to review a PR if someone is interested to contribute. |
I guess this is still broken. I had a similar issue that I was able to fix under puppeteer version 18.1.0 by adding chrome.exe from Windows to $PATH and adding However in the newest version, I get the error FAIL src/App.e2e.test.js
|
I tried everything to get to work. I finally found the answer: import chromium from "@sparticuz/chromium";
const puppeteer = require('puppeteer'); // v20.7.4 or later
(async () => {
const browser = await puppeteer.launch({
executablePath: await chromium.executablePath(),
headless: chromium.headless,
ignoreHTTPSErrors: true,
defaultViewport: chromium.defaultViewport,
args: [...chromium.args, "--hide-scrollbars", "--disable-web-security"],
});
// ...
})().catch(err => {
console.error(err);
process.exit(1);
}); |
Does anyone know the command |
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:
Have tried:
... which doesn't help.
Only other mention I can find of Puppeteer on WSL is #290 (comment).
The text was updated successfully, but these errors were encountered: