question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Can't run Puppeteer Sharp in Docker

See original GitHub issue

Description

I am not able to run Puppeteer Sharp in a Windows docker container. It gives an error while trying to launch chromium.

Complete minimal example reproducing the issue

            var options = new LaunchOptions
            {
                Headless = true
            };

            Console.WriteLine("Downloading chromium");
            await Downloader.CreateDefault().DownloadRevisionAsync(Downloader.DefaultRevision);

            Console.WriteLine("Navigating google");
            using (var browser = await Puppeteer.LaunchAsync(options, Downloader.DefaultRevision))
            using (var page = await browser.NewPageAsync())
            {
                await page.GoToAsync("http://www.google.com");

                Console.WriteLine("Generating PDF");
                await page.PdfAsync(Path.Combine(Directory.GetCurrentDirectory(), "google.pdf"));

                Console.WriteLine("Export completed");
                Console.ReadLine();
            }

Actual behavior:

Downloading chromium
Navigating google

Unhandled Exception: PuppeteerSharp.ChromeProcessException: Failed to create connection ---> PuppeteerSharp.ChromeProcessException: Failed to launch chrome!
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at PuppeteerSharp.Launcher.<LaunchAsync>d__16.MoveNext()
   --- End of inner exception stack trace ---
   at PuppeteerSharp.Launcher.<LaunchAsync>d__16.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at PuppeteerSharpTest.Program.<MainAsync>d__1.MoveNext() in C:\Users\xxx\source\repos\PuppeteerSharpTest\PuppeteerSharpTest\Program.cs:line 27
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at PuppeteerSharpTest.Program.Main(String[] args) in C:\Users\xxx\source\repos\PuppeteerSharpTest\PuppeteerSharpTest\Program.cs:line 13

Versions

Docker

Client:
 Version:      18.03.1-ce
 API version:  1.37
 Go version:   go1.9.5
 Git commit:   9ee9f40
 Built:        Thu Apr 26 07:12:48 2018
 OS/Arch:      windows/amd64
 Experimental: false
 Orchestrator: swarm

Server:
 Engine:
  Version:      18.03.1-ce
  API version:  1.37 (minimum version 1.24)
  Go version:   go1.9.5
  Git commit:   9ee9f40
  Built:        Thu Apr 26 07:21:42 2018
  OS/Arch:      windows/amd64
  Experimental: false

Dotnet

.NET Command Line Tools (2.1.200)

Product Information:
 Version:            2.1.200
 Commit SHA-1 hash:  2edba8d7f1

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.15063
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\2.1.200\

Microsoft .NET Core Shared Framework Host

  Version  : 2.0.7
  Build    : 2d61d0b043915bc948ebf98836fefe9ba942be11

Additional Information

Publish

dotnet publish -o out

Dockerfile

FROM microsoft/aspnetcore
WORKDIR /app
COPY out/ .
ENTRYPOINT ["dotnet", "PuppeteerSharpTest.dll"]

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:15 (5 by maintainers)

github_iconTop GitHub Comments

20reactions
shoe-diamentecommented, Aug 26, 2020

For the record I was able to make it work just via:

RUN apt-get update && apt-get install -y xorg openbox libnss3 libasound2

(in my Dockerfile) and:

var browser = await Puppeteer.LaunchAsync(new LaunchOptions
{
    Headless = true,
    Args = new string[] { "--no-sandbox" }
});

in my launch code.

13reactions
DdannyBcommented, Nov 9, 2018

This is what I used in my dockerfile for installing the dependencies for chrome/puppeteer:

FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app

RUN apt-get update

RUN apt-get install -y wget unzip fontconfig locales gconf-service libasound2 libatk1.0-0 libc6 libcairo2 libcups2 libdbus-1-3 libexpat1 libfontconfig1 libgcc1 libgconf-2-4 libgdk-pixbuf2.0-0 libglib2.0-0 libgtk-3-0 libnspr4 libpango-1.0-0 libpangocairo-1.0-0 libstdc++6 libx11-6 libx11-xcb1 libxcb1 libxcomposite1 libxcursor1 libxdamage1 libxext6 libxfixes3 libxi6 libxrandr2 libxrender1 libxss1 libxtst6 ca-certificates fonts-liberation libappindicator1 libnss3 lsb-release xdg-utils wget

and this is the code I used to warmup chrome:

public HeadlessChrome()
        {

            _options = new LaunchOptions
            {
                Headless = true,
                Args = new string[] { "--no-sandbox" }
            };
            DownloadChrome().ConfigureAwait(true).GetAwaiter().GetResult();
        }

        private async Task DownloadChrome()
        {
            BrowserFetcher browserFetcher = new BrowserFetcher();
            var folder = browserFetcher.DownloadsFolder;
            await browserFetcher.DownloadAsync(BrowserFetcher.DefaultRevision);

            if (System.Runtime.InteropServices.RuntimeInformation
                                   .IsOSPlatform(OSPlatform.Linux))
            {
                var path = Launcher.GetExecutablePath();
                Bash($"chmod 777 {path}");
            }
        }

        public void Bash(string cmd)
        {
            var escapedArgs = cmd.Replace("\"", "\\\"");

            var process = new Process()
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName = "/bin/bash",
                    Arguments = $"-c \"{escapedArgs}\"",
                    RedirectStandardOutput = true,
                    UseShellExecute = false,
                    CreateNoWindow = true,
                }
            };
            process.Start();
            string result = process.StandardOutput.ReadToEnd();
            process.WaitForExit();
        }

The only “problem” I had so far is it didnt install some fonts for example calibri but i’m looking into that.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Running Puppeteer-Sharp on Docker | Darío Kondratiuk
Fixed it, there is an issue because of puppeteer recipe was placed at wrong place so moved recipe inside final stage in build...
Read more >
How to get Puppeteer-Sharp working on an AWS Elastic ...
I'm looking for an up-to-date example of how to get PuppeteerSharp running on an AWS Elastic Beanstalk instance running Docker (.
Read more >
How to use Puppeteer inside a Docker container
I have been trying to run @unlighthouse and Puppeteer in a docker for two days now, with nothing working. I installed Chrome in...
Read more >
Running Puppeteer under Docker
I recently tried to dockerise an old hobby project and unsurprisingly, a couple of things broke. Some of these were fairly simple fixes...
Read more >
Running Puppeteer-Sharp on Docker - DevPress官方社区
I get many questions about running Puppeteer-Sharp on Docker. Let's see if we can get a: Let's take a look at the example...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found