Search code examples
cronwebkitplaywright

Why isn't WebKit working when I launch in cron but works when I launch in terminal?


I'm launching a playwright script on WebKit, Firefox, and Chromium on a VPS with Ubuntu 18.04. Using absolute paths on my VPS all three launch and operate properly if I type it into the terminal like this cd /home/me/desktop/myCode && /usr/bin/npm run webkit > /home/me/desktop/errors.log 2>&1. This makes me think that I have properly installed all of the dependencies from here: https://github.com/microsoft/playwright/blob/master/docs/docker/Dockerfile.bionic

However, when I use the exact same script but via cron, Firefox and Chromium launch and operate properly but the Webkit version starts (it does an async request before launching WebKit and this happens), but when WebKit tries to launch it fails the entire program. The cron script looks like this:

8 14 * * * cd /home/me/desktop/myCode && /usr/bin/npm run webkit > /home/me/desktop/errors.log 2>&1

The error looks like this:

events.js:292 
      throw er; // Unhandled 'error' event
      ^

Error: spawn ldconfig ENOENT
    at Process.ChildProcess._handle.onexit (internal/child_process.js:267:19)
    at onErrorNT (internal/child_process.js:469:16)
    at processTicksAndRejections (internal/process/task_queues.js:84:21)
Emitted 'error' event on ChildProcess instance at:
    at Process.ChildProcess._handle.onexit (internal/child_process.js:273:12)
    at onErrorNT (internal/child_process.js:469:16)
    at processTicksAndRejections (internal/process/task_queues.js:84:21) {
  errno: 'ENOENT',
  code: 'ENOENT',
  syscall: 'spawn ldconfig',
  path: 'ldconfig',
  spawnargs: [ '-p' ]
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! [email protected] webkit: `cd lib && node runWebkit.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the [email protected] webkit script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

Here's some code in Typescript, in case it's an issue with args passed into webkit:

export const getBrowser = async ({
  headless,
  browserName,
}: {
  headless: boolean;
  browserName: BrowserName;
}) => {
  switch (browserName) {
    case BrowserName.firefox:
      return await playwright.firefox.launch({
        headless: headless,
        args: ["--no-sandbox", "--disable-setuid-sandbox"],
      });
    case BrowserName.webkit:
      return await playwright.webkit.launch({
        headless: headless,
      });
    case BrowserName.chromium:
      return await playwright.chromium.launch({
        headless: headless,
        args: ["--no-sandbox", "--disable-setuid-sandbox"],
      });
  }
};

Solution

  • The core problem here is that Playwright v1.3.0 relies on ldconfig being available in the PATH.

    In cronjob environment, PATH defaults to PATH=/usr/bin:/bin which doesn't include ldconfig which is usually at /sbin/ldconfig.

    Easy workarounds:

    • prefix cronjob with PATH=/usr/bin:/bin:/sbin
    • downgrade to v1.2.1

    I filed https://github.com/microsoft/playwright/issues/3397 to track this; we'll release the fix as part of v1.3.1.

    Sorry for the inconvenience!