Commit 4df5ee8d authored by Tatiana Buldina's avatar Tatiana Buldina Committed by Commit Bot

[ChromeDriver] Fix screenshot size on Retina

Fix screenshot size on Retina screen by setting scale = 1 / device_pixel_ratio

Bug: chromedriver:752, chromedriver:2683
Change-Id: I1b378e2cda6f8b52f67337c754ae18cf2cb8130f
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1772436Reviewed-by: default avatarJohn Chen <johnchen@chromium.org>
Commit-Queue: Tatiana Buldina <buldina@chromium.org>
Cr-Commit-Position: refs/heads/master@{#692284}
parent a6c91a93
......@@ -1719,12 +1719,33 @@ Status ExecuteScreenshot(Session* session,
Status status = session->chrome->ActivateWebView(web_view->GetId());
if (status.IsError())
return status;
std::unique_ptr<base::Value> browser_info;
status = web_view->EvaluateScript(
std::string(),
"({x: document.documentElement.scrollLeft || document.body.scrollLeft,"
" y: document.documentElement.scrollTop || document.body.scrollTop,"
" height: window.innerHeight,"
" width: window.innerWidth,"
" device_pixel_ratio: window.devicePixelRatio})",
&browser_info);
std::unique_ptr<base::DictionaryValue> clip_dict =
std::make_unique<base::DictionaryValue>();
clip_dict->SetDouble("x", browser_info->FindKey("x")->GetDouble());
clip_dict->SetDouble("y", browser_info->FindKey("y")->GetDouble());
clip_dict->SetDouble("height", browser_info->FindKey("height")->GetDouble());
clip_dict->SetDouble("width", browser_info->FindKey("width")->GetDouble());
clip_dict->SetDouble(
"scale",
1 / browser_info->FindKey("device_pixel_ratio")->GetDouble());
base::DictionaryValue screenshot_params;
screenshot_params.SetDictionary("clip", std::move(clip_dict));
std::string screenshot;
status = web_view->CaptureScreenshot(&screenshot, base::DictionaryValue());
status = web_view->CaptureScreenshot(&screenshot, screenshot_params);
if (status.IsError()) {
LOG(WARNING) << "screenshot failed, retrying";
status = web_view->CaptureScreenshot(&screenshot, base::DictionaryValue());
status = web_view->CaptureScreenshot(&screenshot, screenshot_params);
}
if (status.IsError())
return status;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment