1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 13:27:35 +00:00

Browser+WebContent+WebDriver: Move Take Screenshot to WebContent

This commit is contained in:
Timothy Flynn 2022-11-10 13:20:44 -05:00 committed by Linus Groh
parent 40b9d248be
commit de1e882601
9 changed files with 29 additions and 39 deletions

View file

@ -695,28 +695,6 @@ static ErrorOr<String, Web::WebDriver::Error> encode_bitmap_as_canvas_element(Gf
return encoded_string;
}
// 17.1 Take Screenshot, https://w3c.github.io/webdriver/#take-screenshot
Web::WebDriver::Response Session::take_screenshot()
{
// 1. If the current top-level browsing context is no longer open, return error with error code no such window.
TRY(check_for_open_top_level_browsing_context_or_return_error());
// 2. When the user agent is next to run the animation frame callbacks:
// a. Let root rect be the current top-level browsing contexts document elements rectangle.
// b. Let screenshot result be the result of trying to call draw a bounding box from the framebuffer, given root rect as an argument.
auto screenshot = m_browser_connection->take_screenshot();
if (!screenshot.is_valid())
return Web::WebDriver::Error::from_code(Web::WebDriver::ErrorCode::UnableToCaptureScreen, "Unable to capture screenshot"sv);
// c. Let canvas be a canvas element of screenshot results data.
// d. Let encoding result be the result of trying encoding a canvas as Base64 canvas.
// e. Let encoded string be encoding results data.
auto encoded_string = TRY(encode_bitmap_as_canvas_element(*screenshot.bitmap()));
// 3. Return success with data encoded string.
return JsonValue { encoded_string };
}
// 17.2 Take Element Screenshot, https://w3c.github.io/webdriver/#dfn-take-element-screenshot
Web::WebDriver::Response Session::take_element_screenshot(StringView parameter_element_id)
{