Node.js 无头Chrome浏览器无法在windows容器上启动?
我正在使用windows nanoserver容器来启动Puppeter,但它失败了,我不确定我的代码出了什么问题 这是我的docker文件Node.js 无头Chrome浏览器无法在windows容器上启动?,node.js,windows,docker,puppeteer,google-chrome-headless,Node.js,Windows,Docker,Puppeteer,Google Chrome Headless,我正在使用windows nanoserver容器来启动Puppeter,但它失败了,我不确定我的代码出了什么问题 这是我的docker文件 FROM mcr.microsoft.com/windows/nanoserver:1903 COPY nodejs /windows/system32 CMD [ "node.exe" ] COPY package.json ./ RUN npm install # Bundle app source COPY . . EN
FROM mcr.microsoft.com/windows/nanoserver:1903
COPY nodejs /windows/system32
CMD [ "node.exe" ]
COPY package.json ./
RUN npm install
# Bundle app source
COPY . .
ENTRYPOINT [ "node", "./server.js" ]
nodejs是我机器上的节点文件夹中的
这是我的package.json
{
"dependencies": {
"puppeteer": "^5.5.0",
"@axe-core/puppeteer": "^4.1.0"
}
}
这是我的server.js
const { AxePuppeteer } = require('@axe-core/puppeteer');
const puppeteer = require('puppeteer');
(async () => {
const browser = await puppeteer.launch({ headless: true,
ignoreDefaultArgs: ['--disable-extensions'],
args: ['--disable-dev-shm-usage', '--no-sandbox', '--disable-gpu', '--disable-setuid-sandbox'],
});
const page = await browser.newPage();
await page.goto('https://stackoverflow.com/');
const results = await new AxePuppeteer(page).analyze();
console.log(results);
await page.close();
await browser.close();
})();
因此,如果我构建docker映像,然后运行
docker build -t chromeHeadless
docker run chromeHeadless
我得到这个错误
(node:1228) UnhandledPromiseRejectionWarning: Error: Failed to launch the browser process!
TROUBLESHOOTING: https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md
at onClose (C:\app\node_modules\puppeteer\lib\cjs\puppeteer\node\BrowserRunner.js:193:20) at Interface.<anonymous> (C:\app\node_modules\puppeteer\lib\cjs\puppeteer\node\BrowserRunner.js:183:68)
at Interface.emit (events.js:326:22)
at Interface.close (readline.js:424:8)
at Socket.onend (readline.js:202:10)
at Socket.emit (events.js:326:22)
at endReadableNT (_stream_readable.js:1244:12)
at processTicksAndRejections (internal/process/task_queues.js:80:21)
(Use `node --trace-warnings ...` to show where the warning was created)
(node:1228) 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(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:1228) [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.
(节点:1228)未处理的Promisejection警告:错误:无法启动浏览器进程!
故障排除:https://github.com/puppeteer/puppeteer/blob/main/docs/troubleshooting.md
在接口处立即关闭(C:\app\node\u modules\puppeter\lib\cjs\puppeter\node\BrowserRunner.js:193:20)。(C:\app\node\u modules\puppeter\lib\cjs\puppeter\node\BrowserRunner.js:183:68)
在Interface.emit(events.js:326:22)
在Interface.close(readline.js:424:8)
位于Socket.onend(readline.js:202:10)
在Socket.emit(events.js:326:22)
在endReadableNT(_stream_readable.js:1244:12)
在处理和拒绝时(内部/process/task_queues.js:80:21)
(使用`node--trace warnings…`显示警告的创建位置)
(节点:1228)未处理的PromisejectionWarning:未处理的承诺拒绝。此错误源于在没有catch块的异步函数中抛出,或者拒绝未使用.catch()处理的承诺。要在未处理的承诺拒绝时终止节点进程,请使用CLI标志“---unhandled rejections=strict”(请参阅https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (拒绝id:1)
(节点:1228)[DEP0018]弃用警告:未处理的承诺拒绝已弃用。将来,未处理的承诺拒绝将使用非零退出代码终止Node.js进程。