webdriver: Wait animation frame callbacks before taking (element) screenshot (#39539)

According to spec, we should wait animation frame callbacks before
taking (element) screenshot. As "element screenshot" would automatically
scroll into view, this solves intermittency.

Testing: Manually tested on pages, and
`take_element_screenshot/scroll_into_view.py` passes stably now.
Fixes: #39306

---------

Signed-off-by: Euclid Ye <yezhizhenjiakang@gmail.com>
This commit is contained in:
Euclid Ye 2025-09-27 21:29:44 +08:00 committed by GitHub
parent 5f5f2abc0f
commit 6aa82309c3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 7 additions and 4 deletions

View file

@ -1223,7 +1223,7 @@ impl IOCompositor {
} }
/// Render the WebRender scene to the active `RenderingContext`. If successful, trigger /// Render the WebRender scene to the active `RenderingContext`. If successful, trigger
/// the next round of animations. /// the next round of animations. Return false if unable to render.
pub fn render(&mut self) -> bool { pub fn render(&mut self) -> bool {
self.global self.global
.borrow() .borrow()

View file

@ -1065,6 +1065,7 @@ impl Servo {
if let Err(e) = response_sender.send(Err(())) { if let Err(e) = response_sender.send(Err(())) {
error!("Sending reply to create png failed {e:?}"); error!("Sending reply to create png failed {e:?}");
} }
return;
} }
} }

View file

@ -2312,6 +2312,11 @@ impl Handler {
} }
fn take_screenshot(&self, rect: Option<Rect<f32, CSSPixel>>) -> WebDriverResult<String> { fn take_screenshot(&self, rect: Option<Rect<f32, CSSPixel>>) -> WebDriverResult<String> {
// Spec: Take screenshot after running the animation frame callbacks.
let _ = self.handle_execute_async_script(JavascriptCommandParameters {
script: "requestAnimationFrame(() => arguments[0]());".to_string(),
args: None,
});
let webview_id = self.webview_id()?; let webview_id = self.webview_id()?;
let mut img = None; let mut img = None;

View file

@ -1,3 +0,0 @@
[scroll_into_view.py]
[test_scroll_into_view]
expected: FAIL