microsoft / playwright-dotnet

.NET version of the Playwright testing and automation library.
https://playwright.dev/dotnet/
MIT License
2.51k stars 239 forks source link

[Bug]: playwright breaks to set content and load chromium with C# code #3061

Closed DipakTated closed 8 hours ago

DipakTated commented 6 days ago

Version

1.40.0

Steps to reproduce

This is the code written in C#

using var playwright = await Playwright.CreateAsync().ConfigureAwait(false);

_logger.Information("Playwright starting to launch chromium"); // Open a new instance of the Google Chrome browser in headless mode await using var browser = await playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions { Headless = true }).ConfigureAwait(false); _logger.Information("Playwright launched chromium"); const int SM_CXSCREEN = 0; const int SM_CYSCREEN = 1;

// Get the screen resolution int screenWidth = GetSystemMetrics(SM_CXSCREEN); int screenHeight = GetSystemMetrics(SM_CYSCREEN); // Create a new page in the browser var page = await browser.NewPageAsync(new BrowserNewPageOptions { ViewportSize = new ViewportSize { Width = screenWidth, Height = screenHeight }, }).ConfigureAwait(false);

await page.SetContentAsync(result).ConfigureAwait(false);

Expected behavior

It should run without errors and load the html content

Actual behavior

while running this code, it throws this error sometimes and it happens once in 20 runs:

2024-11-20 13:48:26.092 +05:30 [Information] Playwright starting to launch chromium
2024-11-20 13:48:30.266 +05:30 [Information] Playwright launched chromium
2024-11-20 13:48:33.248 +05:30 [Error]    at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at Microsoft.Playwright.Transport.Connection.<InnerSendMessageToServerAsync>d__40`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task)
   at Microsoft.Playwright.Transport.Connection.<WrapApiCallAsync>d__50`1.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.ConfiguredTaskAwaitable.ConfiguredTaskAwaiter.GetResult()
   at Fluke.Core.Local.Library.GraphScreenshot.<RetrieveGraphs>d__2.MoveNext() in C:\jenkins2\workspace\oneqa-biox-qa\core\src\Local\Fluke.Core.Local.Library\GraphScreenshot.cs:line 137
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Fluke.Core.Local.Library.GraphScreenshot.<RetrieveGraphs>d__2.MoveNext() in C:\jenkins2\workspace\oneqa-biox-qa\core\src\Local\Fluke.Core.Local.Library\GraphScreenshot.cs:line 177Page crashed
Call log:
  - setting frame content, waiting until "load"

Additional context

No response

Environment

OS 10.0 windows
mxschmitt commented 6 days ago

the script doesn't compile for me - do you mind sharing a minimal csharp project which surfaces this issue? Ideally a small git repository.

Test112-error commented 5 days ago

the script doesn't compile for me - do you mind sharing a minimal csharp project which surfaces this issue? Ideally a small git repository.

here is a sample csharp project. ConsoleApp1.zip

mxschmitt commented 5 days ago

I was not able to reproduce, I tried on Windows 11, maybe this makes a difference:

Image

Also I installed the browsers via

 pwsh .\ConsoleApp1\bin\Debug\playwright.ps1 instal

Probably it doesn't help but I would try updating to latest Playwright - its usually a good practise.

DipakTated commented 5 days ago

as mentioned, this issue doesnot occur always but once in 20+ trials only. there seems to be problem at playwright transport layer according to me as mentioned in log files:

at System.Runtime.CompilerServices.TaskAwaiter.ValidateEnd(Task task) at Microsoft.Playwright.Transport.Connection.d__40`1.MoveNext()

mxschmitt commented 5 days ago

I see Page crashed which means the page is crashing. I recommend to set DEBUG=pw:browser env var which might give us more hints whats going on. Updating Playwright means using a newer Chromium which might has it fixed.

DipakTated commented 5 days ago

When is newer version v1.49.0 of Playwright going to launch, so we can start using from that?

mxschmitt commented 5 days ago

~ 1 week - I recommend 1.48 so far.