Search code examples
c#.net-corepuppeteer-sharp

Disposing a Page causes a warning. Is this an issue?


I have the following code that creates, then closes a Chrome page via PuppeteerSharp:

var options = new LaunchOptions() {Headless = true, Args = new[] { "--disable-web-security" }};

Browser browser = await Puppeteer.LaunchAsync(options, factory);
Page page = await browser.NewPageAsync();
await page.CloseAsync();
page.Dispose();

The last statement (page.Dispose) causes to write out the following warning:

PuppeteerSharp.Page:Warning: Protocol error: Connection closed. Most likely the page has been closed.

I have the following questions:

  1. Is this a problem? Can I ignore this warning?
  2. Do I need to .Dispose of the page after I close it?

Solution

  • You don't need to call Dispose if you call CloseAsync. Dispose is just a fire and forget call to CloseAsync. See.