Commit 1a347670 authored by Shengfa Lin's avatar Shengfa Lin Committed by Commit Bot

[chromedriver] Fix element screenshot scroll for RTL page

For some RTL page with 0 document.documentElement.scrollLeft and
non 0 document.body.scrollLeft, we should not take the
document.body.scrollLeft to calculate DevTools page.capturescreenshot
depending on doctype.
Instead, we can use window.pageXOffset and pageYOffset that should work
with any doctype.

Bug: chromedriver:3625
Change-Id: I38a06b854d26d6039c89b74d89509ef39a9bc18d
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2482048Reviewed-by: default avatarJohn Chen <johnchen@chromium.org>
Commit-Queue: Shengfa Lin <shengfa@google.com>
Cr-Commit-Position: refs/heads/master@{#818532}
parent 9b6dc58f
...@@ -993,8 +993,8 @@ Status ExecuteElementScreenshot(Session* session, ...@@ -993,8 +993,8 @@ Status ExecuteElementScreenshot(Session* session,
// view port. However, CaptureScreenshot expects a location relative to the // view port. However, CaptureScreenshot expects a location relative to the
// document origin. We make the adjustment using the scroll amount of the top // document origin. We make the adjustment using the scroll amount of the top
// level window. Scrolling of frames has already been included in |location|. // level window. Scrolling of frames has already been included in |location|.
// Scroll information can be in either document.documentElement or // Use window.pageXOffset and widnow.pageYOffset for scroll information,
// document.body, depending on document compatibility mode. The parentheses // should always return scroll amount regardless of doctype. The parentheses
// around the JavaScript code below is needed because JavaScript syntax // around the JavaScript code below is needed because JavaScript syntax
// doesn't allow a statement to start with an object literal. // doesn't allow a statement to start with an object literal.
// document.documentElement.clientHeight and Width provide viewport height // document.documentElement.clientHeight and Width provide viewport height
...@@ -1002,8 +1002,8 @@ Status ExecuteElementScreenshot(Session* session, ...@@ -1002,8 +1002,8 @@ Status ExecuteElementScreenshot(Session* session,
std::unique_ptr<base::Value> browser_info; std::unique_ptr<base::Value> browser_info;
status = web_view->EvaluateScript( status = web_view->EvaluateScript(
std::string(), std::string(),
"({x: document.documentElement.scrollLeft || document.body.scrollLeft," "({x: window.pageXOffset,"
" y: document.documentElement.scrollTop || document.body.scrollTop," " y: window.pageYOffset,"
" height: document.documentElement.clientHeight," " height: document.documentElement.clientHeight,"
" width: document.documentElement.clientWidth," " width: document.documentElement.clientWidth,"
" device_pixel_ratio: window.devicePixelRatio})", " device_pixel_ratio: window.devicePixelRatio})",
......
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