簡體   English   中英

木偶無頭Chrome是否可以在Azure App Service的Windows容器中工作?

[英]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()選項:

  1. ignoreDefaultArgs: ['--disable-extensions'] (根據故障排除

  2. 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM