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.

Support Puppeteer-Sharp in a Windows Docker

See original GitHub issue

Description

I am not able to run Puppeteer Sharp in a Windows docker container on my machine. Though I have tried it on some other machines on which it is working.

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();
            }

Expected behavior:

No errors .

Actual behavior:

Downloading chromium
Navigating google

Unhandled Exception: System.InvalidOperationException: An attempt was made to transition a task to a final state when it had already completed.
   at System.ThrowHelper.ThrowInvalidOperationException(ExceptionResource resource)
   at PuppeteerSharp.CDPSession.OnClosed()
   at PuppeteerSharp.Connection.OnClose()
   at PuppeteerSharp.Connection.Dispose()
   at PuppeteerSharp.Browser.<CloseAsync>d__48.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 PuppeteerSharp.Browser.Dispose()
   at PuppeteerSharpTest.Program.<MainAsync>d__1.MoveNext() in C:\buildir\Program.cs:line 42
--- 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:\buildir\Program.cs:line 14

Versions

  • PuppeteerSharp - v1.0.1

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

Dockerfile

FROM microsoft/dotnet:sdk as build
WORKDIR /buildir
COPY . /buildir
RUN dotnet build
RUN dotnet publish -o app


FROM microsoft/windowsservercore
RUN @powershell -NoProfile -ExecutionPolicy unrestricted -Command "iex ((new-object net.webclient).DownloadString('https://chocolatey.org/install.ps1'))" && SET PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin
RUN choco install dotnetcore -y
WORKDIR /app
COPY --from=build /buildir/app /app
ENTRYPOINT ["dotnet", "PuppeteerSharpTest.dll"]

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
Abrissirbacommented, Mar 21, 2019

@respel Any guidance on how you managed to get it to work in a windows docker container? I’m getting “Failed to launch chrome” when running in docker.

0reactions
Abrissirbacommented, Mar 22, 2019

I’m still having issues on windows containers. I switched from using nanoserver to servercore and got passed the “Puppeteer fail to launch” but I’m now stuck on another problem. I can launch a browser and add new pages but I am stuck at goToAsync. If I for exaple go to google.com I get “Navigation failed because browser has disconnected!”. I have tried about 5 urls and all but a very simple one, http://vecka.nu, throws the exception. It feels like it is a problem with the server build or that some dependencies are missing but I have no idea how to go forward.

I tried running the same program in a linux container and it worked perfectly. However, I’m not sure if we can use linux containers so my preferred choice would be to have a working windows container with puppeteer sharp

Read more comments on GitHub >

github_iconTop Results From Across the Web

Support Puppeteer-Sharp in a Windows Docker · Issue #319
Description I am not able to run Puppeteer Sharp in a Windows docker container on my machine. Though I have tried it on...
Read more >
Running Puppeteer-Sharp on Docker | Darío Kondratiuk
I tried everything but my code get stuck at Puppeteer.LaunchAsync line in windows Conttainer, works fine locally. Shashank • 2 months ago. Hi ......
Read more >
Is there any windows container guide for puppeteer?
I'm trying to use PuppeteerSharp with .NET Core3.1 in a windows container, is there some necessary dependencies for using puppeteer in ...
Read more >
hardkoded/puppeteer-sharp-base Dockerfile
FROM mcr.microsoft.com/dotnet/core/runtime:2.1 ... Install latest chrome dev package and fonts to support major charsets (Chinese, Japanese, Arabic, Hebrew, ...
Read more >
How to use Puppeteer inside a Docker container
Puppeteer is a Node.js library which provides a high-level API to control Chromium (or Firefox) browsers over the DevTools Protocol. This guide ...
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