From edfacec9c84a40b5842c6ad9c74c8fc135707153 Mon Sep 17 00:00:00 2001 From: batu_hoang <55729155+longvatrong111@users.noreply.github.com> Date: Fri, 11 Jul 2025 15:13:16 +0800 Subject: [PATCH] script_thread: handle_unfocus_msg ignores unfocus request of top-level document (#37955) `ScriptThread::handle_unfocus_msg` ignores unfocus request of top-level document Fix errors in webdriver navigation commands, which may request unfocus on top-level documents. Testing: `tests/wpt/meta/webdriver/tests/classic/back/back.py` `tests/wpt/meta/webdriver/tests/classic/forward/forward.py` Signed-off-by: batu_hoang --- components/script/dom/document.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs index 13438cae3e0..9ac0e122ab4 100644 --- a/components/script/dom/document.rs +++ b/components/script/dom/document.rs @@ -1217,10 +1217,10 @@ impl Document { /// document's container is removed from the top-level browsing context's /// focus chain (not considering system focus). pub(crate) fn handle_container_unfocus(&self, can_gc: CanGc) { - assert!( - self.window().parent_info().is_some(), - "top-level document cannot be unfocused", - ); + if self.window().parent_info().is_none() { + warn!("Top-level document cannot be unfocused"); + return; + } // Since this method is called from an event loop, there mustn't be // an in-progress focus transaction