mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 07:57:46 +00:00
Browser+WebContent+WebDriver: Move Take Screenshot to WebContent
This commit is contained in:
parent
40b9d248be
commit
de1e882601
9 changed files with 29 additions and 39 deletions
|
@ -806,8 +806,7 @@ Web::WebDriver::Response Client::handle_take_screenshot(Vector<StringView> const
|
|||
{
|
||||
dbgln_if(WEBDRIVER_DEBUG, "Handling GET /session/<session_id>/screenshot");
|
||||
auto* session = TRY(find_session_with_id(parameters[0]));
|
||||
auto result = TRY(session->take_screenshot());
|
||||
return make_json_value(result);
|
||||
return session->web_content_connection().take_screenshot();
|
||||
}
|
||||
|
||||
// 17.2 Take Element Screenshot, https://w3c.github.io/webdriver/#dfn-take-element-screenshot
|
||||
|
|
|
@ -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 context’s document element’s 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 result’s data.
|
||||
// d. Let encoding result be the result of trying encoding a canvas as Base64 canvas.
|
||||
// e. Let encoded string be encoding result’s 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)
|
||||
{
|
||||
|
|
|
@ -66,7 +66,6 @@ public:
|
|||
Web::WebDriver::Response add_cookie(JsonValue const& payload);
|
||||
Web::WebDriver::Response delete_cookie(StringView name);
|
||||
Web::WebDriver::Response delete_all_cookies();
|
||||
Web::WebDriver::Response take_screenshot();
|
||||
Web::WebDriver::Response take_element_screenshot(StringView element_id);
|
||||
|
||||
private:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue