microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
66.95k stars 3.67k forks source link

[REGRESSION]: Large pages cut off the bottom when converted to PDF #20565

Closed nmccalme closed 1 year ago

nmccalme commented 1 year ago

Context:

        var playwright = await Playwright.CreateAsync();
        var browser = await playwright.Chromium.LaunchAsync();
        await using IBrowserContext context = await browser.NewContextAsync();
        var webPage = await context.NewPageAsync();
        var response = 
                await webPage.GotoAsync(
                        model.Url!,
                        new PageGotoOptions()
                        {
                            Timeout = model.PageLoadTimeout,
                            WaitUntil = WaitUntilState.Load
                        });
        // Wait for a custom selector to ensure rendering is finished, if provided
        await webPage.WaitForSelectorAsync(
            model.WaitFor,
            new PageWaitForSelectorOptions()
            {
                State = WaitForSelectorState.Attached
            });

        return await webPage.PdfAsync(
            new PagePdfOptions()
            {
                DisplayHeaderFooter = model.Pdf?.DisplayHeaderFooter,
                Format = model.Pdf?.Format,
                Height = model.Pdf?.Height,
                Landscape = model.Pdf?.Landscape,
                PageRanges = model.Pdf?.PageRanges,
                PreferCSSPageSize = model.Pdf?.PreferCssPageSize,
                PrintBackground = model.Pdf?.PrintBackground,
                Margin = GetMargin(model.Pdf?.Margin),
                Scale = model.Pdf?.Scale,
                Width = model.Pdf?.Width
            });

Describe the bug

We are using Playwright to generate PDFs of internal web pages. When we upgraded to 1.28.0, we discovered that pages that rendered into PDFs with multiple pages (tough to determine an exact breaking point, but certainly at 3 PDF pages) started cutting off at the bottom.

dgozman commented 1 year ago

@nmccalme Did you try printing your page to pdf in Google Chrome browser, without Playwright? I think this could be a Chromium change, a new printing feature LayoutNGPrinting was enabled recently.

If things work in Google Chrome, but not with Playwright, could you please provide a publicly accessible page that is printed incorrectly?

nmccalme commented 1 year ago

@dgozman I'm going to close this as a duplicate of Puppeteer bug 9228. Looks like our symptoms are a little bit different, but incorporating the workaround mentioned there (disable LayoutNGPrinting) did work. So we just need to wait for the upstream bugfix to make it in.

pdsuwwz commented 1 year ago

I have just migrated from puppeteer to playwright@1.37.1, reproduced the same problem

Then try to use playwright@1.27.0 and find that it is normal

last-Programmer commented 4 months ago

I am having this issue too wiht latest version of playwright and chroimun version 128.