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.

Throws WebSocketException when launching Chrome

See original GitHub issue

Description

I haven’t tried Puppeteer before and I’m currently struggling a bit with the example code because it fails to launch chromium instance on macOS (throws WebSocketException).

Complete minimal example reproducing the issue

dotnet new console and,

static void Main(string[] args)
{
    var foo = FoobarAsync().Result;
}

static async Task<string> FoobarAsync()
{
    var browserFetcher = new BrowserFetcher();
    await browserFetcher.DownloadAsync(BrowserFetcher.DefaultRevision);
    var launchOptions = new LaunchOptions
    {
        ExecutablePath = browserFetcher.GetExecutablePath(BrowserFetcher.DefaultRevision),
        Headless = true
    };
    using (var browser = await Puppeteer.LaunchAsync(launchOptions))
    {
        var page = await browser.NewPageAsync();
        await page.GoToAsync("http://localhost:5000");
        var pdfOptions = new PdfOptions { Format = PaperFormat.A4, HeaderTemplate = "<h1>HeaderTemplate</h1>", FooterTemplate = "<h1>FooterTemplate</h1>" };
        var pdfData = await page.PdfStreamAsync(pdfOptions);
        return "";
    }
}

Expected behavior:

No exceptions thrown

Actual behavior:

I get an exception as soon as it tries to launch Chromium (... Puppeteer.LaunchAsync(..)). It seems to download Chromium fine, and there is no change if I point ExecutablePath to a local instance of Chrome.

Unhandled Exception: System.AggregateException: One or more errors occurred. (Failed to create connection) ---> PuppeteerSharp.ChromiumProcessException: Failed to create connection ---> System.Net.WebSockets.WebSocketException: Unable to connect to the remote server
   at System.Net.WebSockets.WebSocketHandle.ConnectAsyncCore(Uri uri, CancellationToken cancellationToken, ClientWebSocketOptions options)
   at System.Net.WebSockets.ClientWebSocket.ConnectAsyncCore(Uri uri, CancellationToken cancellationToken)
   at PuppeteerSharp.Transport.WebSocketTransport.CreateDefaultWebSocket(Uri url, IConnectionOptions options, CancellationToken cancellationToken)
   at PuppeteerSharp.Transport.WebSocketTransport.CreateDefaultTransport(Uri url, IConnectionOptions connectionOptions, CancellationToken cancellationToken)
   at PuppeteerSharp.Connection.Create(String url, IConnectionOptions connectionOptions, ILoggerFactory loggerFactory, CancellationToken cancellationToken)
   at PuppeteerSharp.Launcher.LaunchAsync(LaunchOptions options)
   --- End of inner exception stack trace ---
   at PuppeteerSharp.Launcher.LaunchAsync(LaunchOptions options)
   at PuppeteerSharp.Launcher.LaunchAsync(LaunchOptions options)
   at pdf_console.Program.FoobarAsync() in /Users/lgeir/src/pdf-console/Program.cs:line 25
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at pdf_console.Program.Main(String[] args) in /Users/me/src/pdf-console/Program.cs:line 13

Versions

  • PuppeteerSharp 1.12.1
  • .NET Core 2.2.103
  • OS: macOS Mojave (10.14.3)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
lindsvecommented, Mar 26, 2019

Solution: Added 127.0.0.1 to no_proxy environment variable in addition to localhost and other internal domains

0reactions
EdgeHemancommented, Aug 31, 2020

I was getting the same error with below line of code on Windows machine var browser = await Puppeteer.LaunchAsync(new LaunchOptions ());

I tried with below syntax, and error disappears! var browser = await Puppeteer.LaunchAsync(new LaunchOptions {});

Read more comments on GitHub >

github_iconTop Results From Across the Web

Throws WebSocketException when launching Chrome
I get an exception as soon as it tries to launch Chromium ( ... Puppeteer.LaunchAsync(..) ). It seems to download Chromium fine, and...
Read more >
Failed to establish connection with the application instance ...
Failed to establish connection with the application instance in Chrome. This can happen if the websocket connection used by the web tooling is ......
Read more >
WebSocket: error event - Web APIs | MDN
The error event is fired when a connection with a WebSocket has been closed due to an error (some data couldn't be sent...
Read more >
Kee extension 3.7.8 (brave/chrome) won't connect to ...
when starting Firefox or Chrome (and its Kee Addon) this (and some more) pops up: ... WebSocketException' was thrown. at Fleck2.
Read more >
Websockets over TLS 1.2 cause an unexpected exception ...
issue in Mono that it doesn't fill out the exception correctly. Both on Microsoft .Net 4.7.1 and our Mono runtime I get a...
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