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 <longvatrong111@gmail.com>
This commit is contained in:
batu_hoang 2025-07-11 15:13:16 +08:00 committed by GitHub
parent 75c13f1422
commit edfacec9c8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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