puppeteer: Chromium fails to start when calling puppeteer.launch() in Azure App Service

The line const chromeProcess = childProcess.spawn(chromeExecutable, chromeArguments, {}); in puppeteer/lib/Launcher.js is failing for me.

Line numbers in this stack trace might be off since I added logging to my local Launcher.js

{ Error: spawn UNKNOWN
    at exports._errnoException (util.js:1022:11)
    at ChildProcess.spawn (internal/child_process.js:317:11)
    at Object.exports.spawn (child_process.js:491:9)
    at Function.launch (D:\home\site\wwwroot\node_modules\puppeteer\lib\Launcher.js:86:40)
    at Function.launch (D:\home\site\wwwroot\node_modules\puppeteer\lib\Puppeteer.js:25:21)
    at __dirname (D:\home\site\wwwroot\server.js:39:29)
    ...

Environment: Azure App Service OS version: Microsoft Windows Server 2012 x64 Node: 8.1.4

chromeExecutable is D:\home\site\wwwroot\node_modules\puppeteer\.local-chromium\win32-496140\chrome-win32\chrome.exe

When I try to run chrome.exe from the command line inside the App Service I get

The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log or use the command-line sxstrace.exe tool for more detail.

When running locally (Windows 10 x64) I don’t have this issue.

It seems this is related to the redistributables of C/C++ installed (or not) on the system https://answers.microsoft.com/en-us/windows/forum/windows_10-performance/the-google-chrome-is-not-working-in-my-windows-10/8ecaed7a-e6e1-4097-970f-d32aaba5ec6f https://bugs.chromium.org/p/chromium/issues/detail?id=380228

Is there an alternate version of chrome.exe that I can try uploading to see if it resolves the issue?

Thanks!

Edit – It seems using this package in the Azure App Service sandbox might not be an option because of security / processing limitations.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 18
  • Comments: 15 (1 by maintainers)

Commits related to this issue

Most upvoted comments

had same problem and tried to use linux as ops (while you create your web app or web app for container select linux instead of windows ) this solved first part of the problem (it took you out of sandbox restrictions) after that select built -in runtime for your app (in my case selected node 8.x) and deployed it.

at that point I have to install missing necessary shared library dependencies for chrome.
Running Puppeteer in Docker

just use web ssh and install those deps maually

wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - &&\ sh -c 'echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google-chrome.list' &&\ apt-get update &&\ apt-get install -y google-chrome-unstable

now everything ready to use Headless Chrome with Puppeteer but one more gotcha in your code need to be done, chrome has to be launched with no-sanbox flags

let browser = await puppeteer.launch({ args: [ '--no-sandbox', '--disable-setuid-sandbox' ] });

this is the only workaround i could find, hope that helps to someone

I am getting the same issue while launching puppeteer. { Error: spawn UNKNOWN }

Using Azure functions and Node 6.5.

@kaushik-sundar This is where I was hoping to test functionality once support for Node 6.5 landed (which it has now). I’m not surprised some of the same issues appear in Azure Functions as well.

I’ve seen that many of the headless chrome projects in development had explicitly stated they support AWS Lambda but I don’t know enough about headless Chrome, the compatibility ecosystem or Lambda to understand what needs to be done to support that environment or what needs to change to support Azure (which some of the libraries have stated is on their roadmap).

My use-case right now is a simple API for generating PDFs in a consistent way from a block of HTML and CSS (something that is difficult or impossible using browser based methods - like jsPDF).

Anybody was able to start Puputter / Chrome from Azure App Services or Azure Functions? I am getting the same spawn error. Thanks!

const fs = require('fs');
const path = require('path');
const puppeteer = require('puppeteer');
const os = require('os');

module.exports = function (context, req) {
    function failureCallback(error) {
        context.log("--> Failure = '" + error + "'");
    }

    const chromeDir = path.normalize(__dirname + "/../node_modules/puppeteer/.local-chromium/win64-508693/chrome-win32/chrome.exe");
    context.log("--> Chrome Path = " + chromeDir);

    const dir = path.join(os.tmpdir(), '/screenshots');

    if (!fs.existsSync(dir)){
        fs.mkdirSync(dir);
    }

    const screenshotPath = path.join(dir, "example.png");
    context.log("--> Path = " + screenshotPath);

    let browser, page;
    puppeteer.launch({ executablePath: chromeDir, headless: true, args: [ '--no-sandbox', '--single-process', '--disable-gpu' ] })
        .then(b => {
            context.log("----> 1");
            browser = b;
            return browser.newPage();
        }, failureCallback)
        .then(p => {
            context.log("----> 2");
            page = p;
            return p.goto('https://www.example.com');
        }, failureCallback)
        .then(response => {
            context.log("----> 3");
            return page.screenshot({path: screenshotPath, fullPage: true});  
        }, failureCallback)
        .then(r => {
            browser.close();

            context.res = {
                body: "Done!"
            };

            context.done();            
        }, failureCallback);
};

Below is the log:

2017-12-18T04:32:05  Welcome, you are now connected to log-streaming service.
2017-12-18T04:33:05  No new trace in the past 1 min(s).
2017-12-18T04:33:11.400 Function started (Id=89b31468-8a5d-43cd-832f-b641216dffc0)
2017-12-18T04:33:20.578 JavaScript HTTP trigger function processed a request.
2017-12-18T04:33:20.578 --> Chrome Path D:\home\site\wwwroot\node_modules\puppeteer\.local-chromium\win64-508693\chrome-win32\chrome.exe
2017-12-18T04:33:20.578 --> Path = D:\local\Temp\screenshots\example.png
2017-12-18T04:33:20.965 --> Failure = 'Error: spawn UNKNOWN'
2017-12-18T04:33:20.965 ----> 2