Unhandled promise rejection (rejection id: 1): Error: kill ESRCH

Viewed 4683

I've made some research on the Web and SOF, but found nothing really helpful on that error.

I installed Node and Puppeteer with Windows 10 Ubuntu Bash, but didn't manage to make it work, yet I manage to make it work on Windows without Bash on an other machine.

My command is :

    node index.js

My index.js tries to take a screenshot of a page :

    const puppeteer = require('puppeteer');

    async function run() {
    const browser = await puppeteer.launch();
    const page = await browser.newPage();

    await page.goto('https://github.com');
    await page.screenshot({ path: 'screenshots/github.png' });

    browser.close();
    }

    run();

Does anybody know the way I could fix this "Error: kill ESRCH" error?

4 Answers

Points no consider:

  1. Windows bash is not a complete drop-in replacement for Ubuntu bash (yet). There are many cases where different GUI based apps did not work properly. Also, the script might be confused by bash on windows 10. It could think that the os is linux instead of windows.

  2. Windows 10 bash only supports 64-bit binaries, so make sure the node and the chrome version that's used inside is pretty much 64-bit. Puppeteer is using -child.pid to kill the child processes instead of child.pid on windows version. Make sure puppeteer is not getting confused by all these bash/windows thing.

Back to your case.

You are using browser.close() in the function, but it should be await browser.close(), otherwise it's not executing in proper order.

Also, You should try to add await page.close(); before browser.close();.

So the code should be,

await page.close();
await browser.close();

I worked around it by softlinking chrome.exe to node_modules/puppeteer/.../chrome as below

ln -s /mnt/c/Program\ Files\ \(x86\)/Google/Chrome/Application/chrome.exe  node_modules/puppeteer/.local-chromium/linux-515411/chrome-linux/chrome
Related