From cb68c6eaf146fd9c2a0cfb62a9bd889bf641adb8 Mon Sep 17 00:00:00 2001 From: Andrew Kaster Date: Tue, 20 Feb 2024 16:42:46 -0700 Subject: [PATCH] LibWeb: Set size of canvas used to take WebDriver screenshots explicitly The default canvas size is 300x150 pixels. If the element or document we are trying to screenshot for the WebDriver is not at least that size, then we will create a canvas that is wider or taller than the actual element we are painting, resulting in a bunch of transparent pixels falling off the end. This fixes 14 WPT css/CSS2/floats tests that we run in CI, and presumably a ton of other reftests in the WPT test suite. --- Userland/Libraries/LibWeb/WebDriver/Screenshot.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Userland/Libraries/LibWeb/WebDriver/Screenshot.cpp b/Userland/Libraries/LibWeb/WebDriver/Screenshot.cpp index b61430c8c8..4edbeea8a8 100644 --- a/Userland/Libraries/LibWeb/WebDriver/Screenshot.cpp +++ b/Userland/Libraries/LibWeb/WebDriver/Screenshot.cpp @@ -61,6 +61,10 @@ Response capture_element_screenshot(Painter const& painter, Page& page, DOM::Ele auto canvas_element = DOM::create_element(element.document(), HTML::TagNames::canvas, Namespace::HTML).release_value_but_fixme_should_propagate_errors(); auto& canvas = verify_cast(*canvas_element); + // FIXME: Handle DevicePixelRatio in HiDPI mode. + MUST(canvas.set_width(rect.width())); + MUST(canvas.set_height(rect.height())); + if (!canvas.create_bitmap(rect.width(), rect.height())) { encoded_string_or_error = Error::from_code(ErrorCode::UnableToCaptureScreen, "Unable to create a screenshot bitmap"sv); return;