Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
DipakTated opened this issue Nov 20, 2024 · 7 comments
Open

Comments

@DipakTated
Copy link

DipakTated commented Nov 20, 2024

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
@dgozman dgozman transferred this issue from microsoft/playwright Nov 20, 2024
@mxschmitt
Copy link
Member

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
Copy link

Test112-error commented Nov 21, 2024

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
Copy link
Member

mxschmitt commented Nov 21, 2024

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
Copy link
Author

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
Copy link
Member

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
Copy link
Author

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

@mxschmitt
Copy link
Member

~ 1 week - I recommend 1.48 so far.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants