简体   繁体   中英

Does puppeteer headless chrome work in a Windows container in Azure App Service?

UPDATE

As @Joaquín said, the base image was lacking dependencies. After a lot of research along with trial and error, I settled on using the heavy servercore image along with the necessary fonts required by Chrome. You can find my test app and Dockerfile on my github .

I was able to get it running in Azure App Service as a Windows container, but the image is many times larger and much slower startup time than my Linux version. I'm still very new to Docker containers, so it's been interesting so far.


Running my puppeteer app in a Windows container in Azure App Services ends up with UnhandledPromiseRejectionWarning: Error: Failed to launch chrome!

Yet, it works flawlessly in a Linux container in Azure App Services. Do I have to do something particularly special to get it to work in a Windows container? Or is it futile due to the sandboxing limitations in a Windows app service (container or not)? Though, if this were the case, then I would've expected a spawn UNKNOWN error...

Some of the things I've tried included using the following puppeteer.launch() options:

  1. ignoreDefaultArgs: ['--disable-extensions'] (per troubleshooting )

  2. executablePath: '<path_to_chromium>'

Here's the error and stack trace

(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" ]

When it comes down to a Windows Containers, there is no limitation on the App Service sandbox since Hyper-V is being used as the sandbox for containers on App Service.

The only reason for the failure to launch chrome inside the container is that the base image of the Windows Container is missing some dependency that chrome needs.

If you share dockerfile, I would like to repro the issue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM