Skip to content

Instantly share code, notes, and snippets.

@tolu
Last active January 28, 2022 14:20
Show Gist options
  • Save tolu/c802e4e7ee7d95379b05e7defb48026f to your computer and use it in GitHub Desktop.
Save tolu/c802e4e7ee7d95379b05e7defb48026f to your computer and use it in GitHub Desktop.
Puppeteer on WSL
// resource: http://ktkr3d.github.io/2020/01/27/Puppeteer-on-WSL/
// install puppeteer
// > npm i -g puppeteer
// use chrome from windows: add this to ~/.profile
// PATH=/mnt/c/Program\ Files\ \(x86\)/Google/Chrome/Application:$PATH
const puppeteer = require('puppeteer');
const rimraf = require('rimraf');
const USER_DATA_DIR = 'C:\\temp\\puppeteer_user_data';
const USER_DATA_DIR_WSL = '/mnt/c/temp/puppeteer_user_data';
(async function main() {
const browser = await puppeteer.launch({
executablePath: 'chrome.exe',
userDataDir: USER_DATA_DIR,
headless: false,
args: ['--no-sandbox', '--disable-setuid-sandbox']
});
const page = await browser.newPage();
await page.setViewport({
width: 1920,
height: 1080
});
// locate
await page.goto('https://www.google.com');
await page.screenshot({
path: 'pptr-screenshot.jpg'
});
await browser.close();
})().finally(() => {
rimraf(USER_DATA_DIR_WSL, (error) => {
if (error) {
console.error(error);
}
console.log('and were done!')
})
});
@DaveInchy
Copy link

Thanks but this somehow still wont work and gives me an error that chrome instance wasnt able to be spawned. This is still usefull research.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment