mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 15:48:12 +00:00
WebDriver+Browser: Implement GET /session/{id}/screenshot
This doesn't follow the spec to a tee. Our OutOfProcessWebView already has a bitmap that can be used as the window screenshot. Therefore, we can bypass the steps that assume we need to access the window's frame buffer in-flight. We also don't create an HTMLCanvasElement. We would need a Document in the WebDriver process to do so. Instead, we can still run the encoding steps exactly as-is using the screenshot bitmap.
This commit is contained in:
parent
d603585802
commit
1ffaad29e1
8 changed files with 81 additions and 3 deletions
|
@ -54,6 +54,7 @@ Vector<Client::Route> Client::s_routes = {
|
|||
{ HTTP::HttpRequest::Method::POST, { "session", ":session_id", "cookie" }, &Client::handle_add_cookie },
|
||||
{ HTTP::HttpRequest::Method::DELETE, { "session", ":session_id", "cookie", ":name" }, &Client::handle_delete_cookie },
|
||||
{ HTTP::HttpRequest::Method::DELETE, { "session", ":session_id", "cookie" }, &Client::handle_delete_all_cookies },
|
||||
{ HTTP::HttpRequest::Method::GET, { "session", ":session_id", "screenshot" }, &Client::handle_take_screenshot },
|
||||
};
|
||||
|
||||
Client::Client(NonnullOwnPtr<Core::Stream::BufferedTCPSocket> socket, Core::Object* parent)
|
||||
|
@ -732,4 +733,14 @@ ErrorOr<JsonValue, WebDriverError> Client::handle_delete_all_cookies(Vector<Stri
|
|||
return make_json_value(result);
|
||||
}
|
||||
|
||||
// 17.1 Take Screenshot, https://w3c.github.io/webdriver/#take-screenshot
|
||||
// GET /session/{session id}/screenshot
|
||||
ErrorOr<JsonValue, WebDriverError> Client::handle_take_screenshot(Vector<StringView> const& parameters, JsonValue 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue