microsoft / playwright-dotnet

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

[REGRESSION]: NullReferenceException when calling PdfAsync without argument #2841

Closed filzrev closed 9 months ago

filzrev commented 9 months ago

When using Playwright version to 1.41.1 or later. page.PdfAsync() method throw following exception.

NullReferenceException: Object reference not set to an instance of an object. at async Task<byte[[]]> PdfAsync(PagePdfOptions options) in Page.cs:874

Context:

Code Snippet

await await page.PdfAsync();                      // It's works on `1.41.0` but not works on `1.41.1`
await await page.PdfAsync(new PagePdfOptions {}); // It works on both version.

Describe the bug It seems null checks are missing on latest changes. https://github.com/microsoft/playwright-dotnet/blob/main/src/Playwright/Core/Page.cs#L867-L876

I though this problem can be resolved by adding following line. (It's used on ScreenshotAsync method)

options ??= new PagePdfOptions ();

mxschmitt commented 9 months ago

Thanks for filing, I created https://github.com/microsoft/playwright-dotnet/pull/2842 as a fix. (It was caused by a larger refactoring we were doing.)