You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Window load events fire too quickly for auxiliary browsing contexts #43149
Loading this test in Firefox will wait for 3 seconds before the test completes. In Servo this completes instantly. I believe this is caused by the framed document's initial about:blank triggering the conditions to dispatch the load event.
This does not happen when this page is loaded in an iframe instead of using window.open. I actually think this is triggered by the initial about:blank that is loaded in the new auxiliary browsing context before the actual loaded URL.
changed the title [-]Window load events fire too quickly for pages containing iframes[/-][+]Window load events fire too quickly for auxiliary browsing contexts[/+]on Mar 10, 2026
diff --git a/components/script/dom/document.rs b/components/script/dom/document.rs
index 79d8d054485..adfa43217dd 100644
--- a/components/script/dom/document.rs+++ b/components/script/dom/document.rs@@ -2449,6 +2449,8 @@ impl Document {
return;
}
+ println!("Starting load for {}: {}", self.url(), std::backtrace::Backtrace::force_capture());+
self.loader.borrow_mut().inhibit_events();
// The rest will ever run only once per document.
Output:
0:03.90 pid:9869 Starting load for about:blank: 0: script::dom::document::Document::maybe_queue_document_completion
0:03.90 pid:9869 at ./components/script/dom/document.rs:2452:58
0:03.90 pid:9869 1: script::script_thread::ScriptThread::handle_msgs
0:03.90 pid:9869 at ./components/script/script_thread.rs:1521:26
0:03.90 pid:9869 2: script::script_thread::ScriptThread::start
0:03.90 pid:9869 at ./components/script/script_thread.rs:1081:20
diff --git a/components/script/dom/servoparser/mod.rs b/components/script/dom/servoparser/mod.rs
index be369d1d67e..54b07d09f04 100644
--- a/components/script/dom/servoparser/mod.rs+++ b/components/script/dom/servoparser/mod.rs@@ -763,6 +763,7 @@ impl ServoParser {
self.document.set_current_parser(None);
// Step 5. While the list of scripts that will execute when the document has finished parsing is not empty:
+ println!("Finished parsing for {}: {}", self.document.url(), std::backtrace::Backtrace::force_capture());
self.document.start_the_end_loading_phase();
let url = self.tokenizer.url().clone();
self.document.finish_load(LoadType::PageSource(url), cx);
I see the following:
0:03.36 pid:42748 opening window
0:03.42 pid:42748 Finished parsing for about:blank: 0: script::dom::servoparser::ServoParser::finish
0:03.42 pid:42748 at ./components/script/dom/servoparser/mod.rs:766:70
0:03.42 pid:42748 1: script::dom::servoparser::ServoParser::parse_sync
0:03.42 pid:42748 at ./components/script/dom/servoparser/mod.rs:676:18
0:03.42 pid:42748 2: <script::dom::servoparser::ParserContext as script::network_listener::FetchResponseListener>::process_response_eof
0:03.42 pid:42748 at ./components/script/dom/servoparser/mod.rs:1459:20
0:03.42 pid:42748 3: script::script_thread::ScriptThread::start_page_load_about_blank
0:03.42 pid:42748 at ./components/script/script_thread.rs:4025:17
0:03.42 pid:42748 4: script::script_thread::ScriptThread::pre_page_load
0:03.43 pid:42748 at ./components/script/script_thread.rs:3793:18
0:03.43 pid:42748 5: script::script_thread::ScriptThread::spawn_pipeline::{{closure}}
0:03.43 pid:42748 at ./components/script/script_thread.rs:2757:22
0:03.43 pid:42748 6: script::script_thread::ScriptThread::profile_event
0:03.43 pid:42748 at ./components/script/script_thread.rs:1692:13
0:03.43 pid:42748 7: script::script_thread::ScriptThread::spawn_pipeline
0:03.43 pid:42748 at ./components/script/script_thread.rs:2726:14
0:03.43 pid:42748 8: script::dom::windowproxy::WindowProxy::create_auxiliary_browsing_context::{{closure}}
0:03.43 pid:42748 at ./components/script/dom/windowproxy.rs:358:27
0:03.43 pid:42748 9: core::option::Option<T>::map
0:03.43 pid:42748 at /home/tvanderlippe/.rustup/toolchains/1.92.0-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/option.rs:1164:29
0:03.43 pid:42748 10: script::script_thread::with_script_thread::{{closure}}
0:03.43 pid:42748 at ./components/script/script_thread.rs:180:63
0:03.43 pid:42748 11: script::script_thread::with_optional_script_thread::{{closure}}
0:03.43 pid:42748 at ./components/script/script_thread.rs:173:9
0:03.43 pid:42748 12: std::thread::local::LocalKey<T>::try_with
0:03.43 pid:42748 at /home/tvanderlippe/.rustup/toolchains/1.92.0-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/local.rs:508:12
0:03.43 pid:42748 13: std::thread::local::LocalKey<T>::with
0:03.43 pid:42748 at /home/tvanderlippe/.rustup/toolchains/1.92.0-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/local.rs:472:20
0:03.43 pid:42748 14: script::script_thread::with_optional_script_thread
0:03.43 pid:42748 at ./components/script/script_thread.rs:172:24
0:03.43 pid:42748 15: script::script_thread::with_script_thread
0:03.43 pid:42748 at ./components/script/script_thread.rs:180:5
0:03.43 pid:42748 16: script::dom::windowproxy::WindowProxy::create_auxiliary_browsing_context
0:03.43 pid:42748 at ./components/script/dom/windowproxy.rs:357:9
0:03.43 pid:42748 17: script::dom::windowproxy::WindowProxy::choose_browsing_context
0:03.43 pid:42748 at ./components/script/dom/windowproxy.rs:619:31
0:03.43 pid:42748 18: script::dom::windowproxy::WindowProxy::open
0:03.43 pid:42748 at ./components/script/dom/windowproxy.rs:511:40
To me, that seems similar to the logic in iframe_load_event_steps where we check the src attribute if it exists. To unify these two, should we add a bool to LoadData that essentially says "I am the first one, but a second one is coming, so don't think I am finished loading yet"? Then we can use that for both iframes as well as auxiliary windows.
I'm nervous about adding that information to LoadData, but I'll need to think about why. My idea with document replacement is that right now, the only thing linking the about:blank document/window with the subsequent navigation is a browsing context id. If we implement document replacement (see relevant commits from #33087) then it's easier to check "is this document the associated document of the window" and ignore tasks for the old document.
We already have a method for that in the servoparser, but it's mostly empty still. The one tricky bit is that if we create the document value last, we can't eagerly add nodes to it. So it complicates the parser further. Still, I think that's worth it.
This was fixed by the combination of the various PRs that mentioned this issue. Any specific behaviour issues with window.open should be filed as new issues!
Activity
jdm commentedon Mar 10, 2026
This does not happen when this page is loaded in an iframe instead of using
window.open. I actually think this is triggered by the initialabout:blankthat is loaded in the new auxiliary browsing context before the actual loaded URL.jdm commentedon Mar 10, 2026
Even easier to see:
No need for any nested browsing contexts.
[-]Window load events fire too quickly for pages containing iframes[/-][+]Window load events fire too quickly for auxiliary browsing contexts[/+]jdm commentedon Mar 10, 2026
I think one possible solution here is implementing document replacement: https://html.spec.whatwg.org/multipage/nav-history-apis.html#concept-document-window . I'm having a hard time finding the actual spec step where that replacement is supposed to occur.
TimvdLippe commentedon Mar 10, 2026
With the following diff:
Output:
That's this code:
servo/components/script/script_thread.rs
Lines 1516 to 1524 in 4ef22ed
Note that we never log
/common/blank.html?pipe=trickle(d3)as a URL. The URLs we log (in order):TimvdLippe commentedon Mar 10, 2026
#42446 was supposed to fix that quirk, but had other issues with flakiness and such 😢
TimvdLippe commentedon Mar 10, 2026
On https://github.com/TimvdLippe/servo/tree/reintroduce-end-of-loading-phases with
I see the following:
TimvdLippe commentedon Mar 10, 2026
So because in
start_page_load_about_blankwe pretend to have a fetch request, the parser "encounters" the EOF character and we inadvertently trigger the loading sequence (https://html.spec.whatwg.org/multipage/parsing.html#the-end). Ideally we would know that when creating the auxiliary context, we are going to immediately do something with it or not. In the second case, we shouldn't fire.To me, that seems similar to the logic in
iframe_load_event_stepswhere we check thesrcattribute if it exists. To unify these two, should we add a bool toLoadDatathat essentially says "I am the first one, but a second one is coming, so don't think I am finished loading yet"? Then we can use that for both iframes as well as auxiliary windows.jdm commentedon Mar 10, 2026
I'm nervous about adding that information to LoadData, but I'll need to think about why. My idea with document replacement is that right now, the only thing linking the about:blank document/window with the subsequent navigation is a browsing context id. If we implement document replacement (see relevant commits from #33087) then it's easier to check "is this document the associated document of the window" and ignore tasks for the old document.
jdm commentedon Mar 10, 2026
This result doesn't surprise me, because the test calls w.close() after receiving the load event, so the navigation never has a chance to complete.
jdm commentedon Mar 11, 2026
https://html.spec.whatwg.org/multipage/document-lifecycle.html#initialise-the-document-object is the bit I was looking for in the spec where a window's document changes.
TimvdLippe commentedon Mar 11, 2026
We already have a method for that in the servoparser, but it's mostly empty still. The one tricky bit is that if we create the document value last, we can't eagerly add nodes to it. So it complicates the parser further. Still, I think that's worth it.
jdm commentedon Mar 13, 2026
I'm working on document replacement in https://github.com/servo/servo/compare/main...jdm:servo:document-replace?expand=1 .
jdm commentedon Mar 14, 2026
whatwg/html#12259
16 remaining items
constellation: Do not request permission for initial about:blank load…
jdm commentedon Aug 6, 2026
Given the ongoing issues with intermittent test results for #46975, I'm trying a detour into making about:blank really synchronous: https://github.com/servo/servo/compare/main...jdm:servo:sync-about-blank?expand=1
script: Do not navigate a newly-opened window to about:blank. (servo#…
script: Move FontContext into each global that requires it. (servo#47130
script: Make about:blank documents load synchronously without a parse…
script: Use global's active document's navigation timing for Performa…
script: Replace initial about:blank document (servo#46975)
jdm commentedon Aug 21, 2026
This was fixed by the combination of the various PRs that mentioned this issue. Any specific behaviour issues with window.open should be filed as new issues!
constellation: Do not request permission for initial about:blank load…
script: Do not navigate a newly-opened window to about:blank. (servo#…
script: Move FontContext into each global that requires it. (servo#47130
script: Make about:blank documents load synchronously without a parse…
script: Use global's active document's navigation timing for Performa…
script: Replace initial about:blank document (servo#46975)