Closed corygehr closed 3 years ago
@pavelfeldman Thank you so much for resolving the parsing issue, but it looks like that PR doesn't fix our connection dropping issue!
Is there a repro we could use?
@pavelfeldman Sure! https://github.com/dayadam/PlaywrightConnectionRepro4
@pavelfeldman Sure! https://github.com/dayadam/PlaywrightConnectionRepro4
@dayadam @corygehr
IMO there is a bug in your code / repro: await using var browser = await playwright.Chromium.LaunchAsync();
is called from inside separate method GetPageAsync
and await using
is calling DisposeAsync
just after returning "new page".
So in Main
method browser is already disposed.
Pleas refer to general thread about IAsyncDisposable
https://docs.microsoft.com/en-us/dotnet/standard/garbage-collection/implementing-disposeasync#using-async-disposable
Full code from your repro for reference:
using System;
using Microsoft.Playwright;
using System.Threading.Tasks;
namespace PlaywrightDemo5
{
class Program
{
public static async Task Main()
{
var newPage = await GetPageAsync();
await newPage.GotoAsync("https://playwright.dev/");
var locator = newPage.Locator("//div");
var locatorElm2 = locator.Nth(0).Locator("//div").Nth(0);
var locatorHTML = await locatorElm2.InnerHTMLAsync();
}
public static async Task<IPage> GetPageAsync()
{
var playwright = await Playwright.CreateAsync();
await using var browser = await playwright.Chromium.LaunchAsync();
return await browser.NewPageAsync();
}
}
}
@fr4gles you're correct!
This should be fixed in 1.15.
Playwright version
1.14.0
Operating system
Windows
What browsers are you seeing the problem on?
Chromium (default installed by playwright).
Other information
.NET 5
What happened? / Describe the bug
When calling
Locator()
on an existingILocator
object, the method returns but subsequent calls on the returned object throw aPlaywrightException
:I encountered the same issue in Playwright 1.13.x with
IElementHandle
objects. Somehow, it appears the pipe between the .NET wrapper the node driver is getting closed when attempting to do nested Locator calls.In my use case, I want to identify child elements of particular parent HTML nodes. At one point, I managed to get the following exception, but no idea what I did differently to get this to fire:
Code snippet to reproduce your bug
This is a simplified example. In my project, I have a wrapper class for the
ILocator
andIPage
objects but I have no reason to believe the garbage collector is disposing my browser.Relevant log output