Webdriver get focused webview id only request once (#37506)

The retry in previous implementation doesn't have a good reason, it
seems like webdriver just want to try its luck.
If get focused webview return None, better just return it.
There is a case webdriver still runs when all webview are closed.

cc: @xiaochengh

Signed-off-by: batu_hoang <longvatrong111@gmail.com>
This commit is contained in:
batu_hoang 2025-06-18 11:51:08 +08:00 committed by GitHub
parent 50531026a8
commit 152467bc67
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -464,27 +464,18 @@ impl Handler {
fn focus_webview_id(&self) -> WebDriverResult<WebViewId> {
debug!("Getting focused context.");
let interval = 20;
let iterations = 30_000 / interval;
let (sender, receiver) = ipc::channel().unwrap();
for _ in 0..iterations {
let msg =
EmbedderToConstellationMessage::GetFocusTopLevelBrowsingContext(sender.clone());
self.constellation_chan.send(msg).unwrap();
// Wait until the document is ready before returning the top-level browsing context id.
if let Some(x) = receiver.recv().unwrap() {
debug!("Focused context is {}", x);
return Ok(x);
}
thread::sleep(Duration::from_millis(interval));
let msg = EmbedderToConstellationMessage::GetFocusTopLevelBrowsingContext(sender.clone());
self.constellation_chan.send(msg).unwrap();
// Wait until the document is ready before returning the top-level browsing context id.
match wait_for_script_response(receiver)? {
Some(webview_id) => Ok(webview_id),
None => Err(WebDriverError::new(
ErrorStatus::NoSuchWindow,
"No focused webview found",
)),
}
debug!("Timed out getting focused context.");
Err(WebDriverError::new(
ErrorStatus::Timeout,
"Failed to get window handle",
))
}
fn session(&self) -> WebDriverResult<&WebDriverSession> {