playwright-java: [Question] FullPageScreenshot is not capturing the full page

Hi - I have the following script to capture the full page screenshot

@Test
    public void googleTest(){
       Playwright playwright = Playwright.create();
        BrowserType.LaunchOptions launchOptions = new BrowserType.LaunchOptions();
        launchOptions.setHeadless(false)
                .setChannel(BrowserChannel.CHROME);
        Browser browser = playwright.chromium().launch(launchOptions);
        BrowserContext browserContext = browser.newContext();
        Page page = browserContext.newPage();
        page.navigate("https://google.com");
        page.click("text=I agree");
        System.out.println(page.title());
        page.screenshot(new Page.ScreenshotOptions()
                .setPath(Paths.get("colosseum-pixel2.png"))
                .setFullPage(true)
        );

    }

The script runs fine and it takes the screenshot at the end. But the screenshot is not full page. Please refer attached the screenshot.

Screenshot-Taken-By-Playwright

I am running this script using Playwright 1.10.0 OS - Ubuntu 20.04.2

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 18 (9 by maintainers)

Most upvoted comments

Below is a simple test (using 1.11.0) that illustrates the issue.

Here’s the images outputted: https://imgur.com/a/O3C0Dw7

package test;

import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;

import com.microsoft.playwright.Browser;
import com.microsoft.playwright.BrowserContext;
import com.microsoft.playwright.BrowserType;
import com.microsoft.playwright.BrowserType.LaunchOptions;
import com.microsoft.playwright.Page;
import com.microsoft.playwright.Playwright;

public class ScreenshotTest {

	public static void main(String[] args) {
		try (Playwright playwright = Playwright.create()) {
			List<BrowserType> browserTypes = Arrays.asList(playwright.chromium(), playwright.firefox());
			for (BrowserType browserType : browserTypes) {
				for (var headless : List.of(false, true)) {
					for (var swiftshader : List.of(false, true)) {
						var launchOptions = new LaunchOptions().setHeadless(headless);
						if (swiftshader)
							launchOptions.setArgs(List.of("--use-gl=swiftshader"));
						try (Browser browser = browserType.launch(launchOptions)) {
							BrowserContext context = browser.newContext();
							Page page = context.newPage();
							page.navigate(
									"https://stackoverflow.com/questions/33770549/viewport-vs-window-vs-document");
							var path = Paths.get(String.format("temp/screenshot-%s-%s-%s-%s.png", browserType.name(),
									headless ? "headless" : "headfull", swiftshader ? "swiftshader" : "defaultshader",
									UUID.randomUUID().toString()));
							page.screenshot(new Page.ScreenshotOptions().setFullPage(true).setPath(path));
							System.out.println(path.toFile().getAbsolutePath());
						}
					}
				}
			}
		}
	}
}

I can confirm that this is happening. It looks like the viewport gets squashed right before the screenshot is rendered

I get the below output

*-display
description: VGA compatible controller product: UHD Graphics 620 vendor: Intel Corporation physical id: 2 bus info: pci@0000:00:02.0 version: 07 width: 64 bits clock: 33MHz capabilities: pciexpress msi pm vga_controller bus_master cap_list rom configuration: driver=i915 latency=0 resources: irq:134 memory:b0000000-b0ffffff memory:a0000000-afffffff ioport:4000(size=64) memory:c0000-dffff

Sorry for the confusion. In headful mode (launchOptions.setHeadless(false)) passing “–use-gl=swiftshader” also doesn’t solves the problem regardless of ‘’‘setFullPage’‘’ value