I'm trying to get to run puppeteer on WSL2. I've tried using a remote display via VcXsvr but my firewall settings and host have custom changes and I've frankly given up seeing that https://learn.microsoft.com/en-us/windows/wsl/tutorials/gui-apps is in the works.
So in the meantime I'm trying to connect to the Windows Chrome install directly using the following test code:
const puppeteer = require('puppeteer');
const EXECUTABLE_PATH = '/mnt/c/Users/[username]/AppData/Local/Google/Chrome/Application/chrome.exe';
const USER_DATA_DIR = 'C:\\Users\\[username]\\AppData\\Local\\Google\\Chrome\\User Data';
const url = process.argv[2];
console.log(url);
if (!url) {
throw "Please provide URL as a first argument";
}
async function run () {
try {
const browser = await puppeteer.launch({
executablePath: EXECUTABLE_PATH,
userDataDir: USER_DATA_DIR,
headless: false,
ignoreDefaultArgs: ['--disable-extensions'],
});
const page = await browser.newPage();
await page.goto(url);
await page.screenshot({path: 'screenshot.png'});
browser.close();
} catch(err){
console.log(err)
}
}
run();
I'm seeing chrome open but then showing the following error:
Error: Failed to launch the browser process!
[4348:24368:0526/115831.752:ERROR:cache_util_win.cc(20)] Unable to move the cache: Access is denied. (0x5)
[4348:24368:0526/115831.753:ERROR:cache_util.cc(144)] Unable to move cache folder C:\Users\[username]\AppData\Local\Google\Chrome\User Data\ShaderCache\GPUCache to C:\Users\[username]\AppData\Local\Google\
Chrome\User Data\ShaderCache\old_GPUCache_001
[4348:24368:0526/115831.753:ERROR:disk_cache.cc(184)] Unable to create cache
[4348:24368:0526/115831.753:ERROR:shader_disk_cache.cc(606)] Shader Cache Creation failed: -2
TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md
at onClose (~/development/my-puppeteer-app/node_modules/puppeteer/lib/launcher/BrowserRunner.js:189:20)
at Interface.helper_1.helper.addEventListener (~/development/my-puppeteer-app/node_modules/puppeteer/lib/launcher/BrowserRunner.js:179:65)
at Interface.emit (events.js:203:15)
at Interface.close (readline.js:397:8)
at Socket.onend (readline.js:173:10)
at Socket.emit (events.js:203:15)
at endReadableNT (_stream_readable.js:1145:12)
at process._tickCallback (internal/process/next_tick.js:63:19)
I cannot figure out how to fix this from the provided troubleshooting link and cannot find any other sources where this is shown. Any suggestions would be welcome.
USER_DATA_DIR
the same format asEXECUTABLE_PATH
starting with/mnt/c/...
– Heartwood