![](/img/trans.png)
[英]How to make Puppeteer or Playwright to work on Azure Web App Service (Linux )
[英]Does puppeteer headless chrome work in a Windows container in Azure App Service?
UPDATE
正如@Joaquín所说,基本映像缺少依赖项。 经过大量研究和反复试验,我决定使用沉重的servercore图像以及Chrome所需的必要字体 。 您可以在github上找到我的测试应用程序和Dockerfile。
我能够使它作为Windows容器在Azure App Service中运行,但是该映像比Linux版本大很多倍,启动时间也慢得多。 我对Docker容器还是很陌生,所以到目前为止,它很有趣。
在Azure App Services的Windows容器中运行我的puppeteer应用程序最终显示为UnhandledPromiseRejectionWarning: Error: Failed to launch chrome!
但是,它可以在Azure App Services的Linux容器中完美地工作。 我必须要做一些特别的事情才能使其在Windows容器中工作吗? 还是由于Windows应用程序服务(是否包含容器)中的沙箱限制而徒劳? 不过,如果是这种情况,那么我会期望spawn UNKNOWN
一个spawn UNKNOWN
错误...
我尝试过的一些事情包括使用以下puppeteer.launch()选项:
ignoreDefaultArgs: ['--disable-extensions']
(根据故障排除 )
executablePath: '<path_to_chromium>'
这是错误和堆栈跟踪
(node:1272) UnhandledPromiseRejectionWarning: Error: Failed to launch chrome!
TROUBLESHOOTING: https://github.com/GoogleChrome/puppeteer/blob/master/docs/troubleshooting.md
at onClose (C:\app\node_modules\puppeteer\lib\Launcher.js:349:14)
at Interface.helper.addEventListener (C:\app\node_modules\puppeteer\lib\Launcher.js:338:50)
at Interface.emit (events.js:203:15)
at Interface.close (readline.js:397:8)
at Socket.onend (readline.js:173:10)
at Socket.emit (events.js:203:15)
at endReadableNT (_stream_readable.js:1129:12)
at process._tickCallback (internal/process/next_tick.js:63:19)
(node:1272) 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:1272) [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.
Dockerfile
ARG core=mcr.microsoft.com/windows/servercore:ltsc2019
ARG target=mcr.microsoft.com/windows/nanoserver:1809
FROM $core as download
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
ENV NODE_VERSION 10.16.0
RUN Invoke-WebRequest $('https://nodejs.org/dist/v{0}/node-v{0}-win-x64.zip' -f $env:NODE_VERSION) -OutFile 'node.zip' -UseBasicParsing ; \
Expand-Archive node.zip -DestinationPath C:\ ; \
Rename-Item -Path $('C:\node-v{0}-win-x64' -f $env:NODE_VERSION) -NewName 'C:\nodejs'
FROM $target
COPY --from=download /nodejs/ /nodejs/
USER Administrator
RUN setx /M PATH "%PATH%;C:\nodejs"
RUN mkdir "C:\app"
WORKDIR "C:\app"
COPY . .
RUN npm install
EXPOSE 8000
CMD [ "node.exe", "server.js" ]
归结为Windows容器时,对App Service沙箱没有任何限制,因为Hyper-V被用作App Service上容器的沙箱。
无法在容器内启动chrome的唯一原因是Windows容器的基本映像缺少chrome需要的某些依赖项。
如果您共享dockerfile,我想重现该问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.