Throws WebSocketException when launching Chrome
See original GitHub issueDescription
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:
- Created 4 years ago
- Comments:8 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Solution: Added
127.0.0.1
tono_proxy
environment variable in addition tolocalhost
and other internal domainsI 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 {});