木偶从终端工作,但从crontab失败

时间:2020-02-07 11:22:14

标签: cron puppeteer grafana

寻求专家的帮助。从终端运行Puppeteer时,它可以按预期运行并生成pdf文件(脚本的一部分为const browser = await puppeteer.launch();

通过shell运行会生成pdf文件

$ /bin/sh /tmp/grafana_report_pup.sh

grafana_report_pup.sh

node /tmp/grafana_pdf.js http://localhost:3000/d/qP-sbQEZz/new-dashboard?kiosk $GF_USER:$GF_PASSWORD $GF_OUT

问题出现在我放入crontab时:

# m h  dom mon dow   command
44 10 * * * /bin/sh /tmp/grafana_report_pup.sh  > /tmp/graf.log 2>&1

我收到有关没有沙箱的错误,因此建议我传递参数:

const browser = await puppeteer.launch({args: ['--no-sandbox', '--disable-setuid-sandbox']});

即使使用建议的参数,从crontab运行也会产生以下错误

(node:56385) UnhandledPromiseRejectionWarning: Error: Evaluation failed: TypeError: Cannot read property 'getBoundingClientRect' of undefined
    at __puppeteer_evaluation_script__:2:67
    at ExecutionContext._evaluateInternal (/tmp/node_modules/puppeteer/lib/ExecutionContext.js:122:13)
    at process._tickCallback (internal/process/next_tick.js:68:7)
  -- ASYNC --
    at ExecutionContext.<anonymous> (/tmp/node_modules/puppeteer/lib/helper.js:111:15)
    at DOMWorld.evaluate (/tmp/node_modules/puppeteer/lib/DOMWorld.js:112:20)
    at process._tickCallback (internal/process/next_tick.js:68:7)
  -- ASYNC --
    at Frame.<anonymous> (/tmp/node_modules/puppeteer/lib/helper.js:111:15)
    at Page.evaluate (/tmp/node_modules/puppeteer/lib/Page.js:860:43)
    at Page.<anonymous> (/tmp/node_modules/puppeteer/lib/helper.js:112:23)
    at /tmp/grafana_pdf.js:59:30
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:56385) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:56385) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Link to grafana_pdf.js

0 个答案:

没有答案