我有一个伪造者问题-每次尝试拍摄另一个网站的屏幕截图时,我都会收到此错误:
(node:2359) UnhandledPromiseRejectionWarning: Error: socket hang up
at createHangUpError (_http_client.js:313:15)
at Socket.socketOnEnd (_http_client.js:409:23)
at Socket.emit (events.js:187:15)
at endReadableNT (_stream_readable.js:1086:12)
at process._tickCallback (internal/process/next_tick.js:63:19)
(node:2359) 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:2359) [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.
这是我尝试从SSH执行的脚本:
const http = require('http');
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({ args: ['--no-sandbox']});
const page = await browser.newPage();
await page.setViewport({ width: 780, height: 580 });
await page.goto('https://www.google.pl/');
await page.waitFor(15200);
await page.screenshot({path: 'testScreenshot.jpg'});
await browser.close();
})();
我不知道我在做什么错,我已经安装了所有缺少的依赖项,缺少的库等,并且仍然收到此错误。
我正在使用CentOS7,NodeJS 10.1.0和NPM 5.6.0。
具有相同库和相同依存关系等的相同脚本在装有OS 3.13.0-44通用GNU / Linux的流浪汉机器上运行良好。
我正在以su特权从SSH执行nodejs脚本。
我也在尝试安装缺少的库:
yum install pango.x86_64 libXcomposite.x86_64 libXcursor.x86_64
libXdamage.x86_64 libXext.x86_64 libXi.x86_64 libXtst.x86_64 cups-
libs.x86_64 libXScrnSaver.x86_64 libXrandr.x86_64 GConf2.x86_64 alsa-
lib.x86_64 atk.x86_64 gtk3.x86_64 -y
然后centos表示没有要安装的新东西,但是套接字挂起仍然出现错误。
哦,我也忘记了我对package.json的依赖:
"dependencies": {
"chromium": "^1.0.2",
"puppeteer": "^1.8.0",
"puppeteer-core": "^1.8.0"
}