Skip to content

Truly independent web browser

LibWeb: Report page rendering work still pending

Andreas Kling8cc943d2a445
diff --git a/Documentation/StatsLog.md b/Documentation/StatsLog.md
index fd7a329d8d1..0470d2799db 100644
--- a/Documentation/StatsLog.md
+++ b/Documentation/StatsLog.md
@@ -113,6 +113,7 @@ form `namespace:local`, preserving their exact values in floating-point JSON con
| `DOMContentLoaded` | WebContent | `page_id` (integer), `navigable_id` (cross-process ID string), `document_id` (cross-process ID string), `url` (string) |
| `load` | WebContent | Same fields as `DOMContentLoaded` |
| `frame` | Compositor | `page_id` (integer), `changed` (boolean), `damage_x`, `damage_y`, `damage_width`, `damage_height` (integer device pixels) |
+| `rendering_pending` | WebContent | `page_id` (integer), `navigable_id` (cross-process ID string), `pending` (boolean), `reasons` (object of integer counts) |
| `gc` | WebContent or WebWorker | `collection`, `duration_ns`, `pause_duration_ns`, `sweep_duration_ns`, `bytes_before`, `bytes_after`, `live_cell_bytes`, `live_external_bytes` (integers) |
Navigation starts are recorded when the browser admits a navigation. Lifecycle markers are recorded
@@ -122,8 +123,10 @@ start without new lifecycle events. Canceled navigations may never produce lifec
Detached documents and decoded SVG image documents do not produce lifecycle markers.
GC events are written after sweeping finishes. Durations measure active collection work, excluding
-idle time between incremental sweep slices. Byte counts describe the heap's existing accounting,
-not process RSS.
+idle time between incremental sweep slices. `pause_duration_ns` includes marking, finalization and
+synchronous sweep or incremental-sweep setup.
+`sweep_duration_ns` sums incremental block sweeps; `duration_ns` is their sum. `bytes_before` and
+`bytes_after` count owned heap block bytes, including unused slots. They are not process RSS.
The compositor records a frame immediately before publishing its rendered surface to the browser.
GPU work has completed, or on Metal has been scheduled for the receiving surface to wait on.
@@ -135,11 +138,53 @@ produce identical colors. No readback or pixel hashing is performed. Fully suppr
produce events. The last changed frame after a bounded quiet period gives a conservative estimate of
when the page finished painting. Animation and media can keep producing changed frames indefinitely.
+## Pending rendering work
+
+`rendering_pending` reports the page's active documents hosted in this WebContent process. Changes
+coalesce across an HTML task and its microtasks, or at the Core event-loop boundary for other engine
+callbacks. The first snapshot establishes state; subsequent snapshots are written only when totals
+change. Replace snapshots by `(pid, page_id)` and combine live pages sharing `navigable_id` for
+isolated frames. Absence of a snapshot is unknown, not idle.
+
+Detached, destroyed and decoded SVG image documents are excluded. Hidden documents and frames with
+no displayed viewport are excluded from every counter. Display eligibility uses the existing
+container viewport report, visibility state and local-root viewport intersection. This excludes
+zero-size, offscreen and undisplayed frames; it does not test pixel occlusion by other elements.
+A newly attached child contributes after its first displayed viewport report. A stats-only display
+eligibility notification is routed through the browser to isolated hosts, including descendants when
+an embedding changes. It carries no presentation identities and does not change viewport geometry,
+web visibility or rendering decisions.
+
+`pending` is true when any of these `reasons` is nonzero. All keys are always present:
+
+| Reason | Count |
+| --- | --- |
+| `needs_rendering_update` | Documents with an invalidation not consumed by a presentation commit or a no-op rendering update |
+| `image_decodes` | Initial shared image decodes and window `createImageBitmap(Blob)` operations awaiting completion, failure or stop |
+| `font_loads` | Entries in document `FontFaceSet` loading lists |
+| `style_sheet_loads` | Pending stylesheet-request delayers plus pending CSS import rules |
+| `resource_fetches_in_flight` | Window-client fetches through final response source completion, failure or cancellation |
+| `scheduled_animation_frame_callbacks` | Window callbacks awaiting the next animation-frame callback batch |
+| `load_event_delayers` | Existing document load-event delayers |
+| `document_loads` | Documents whose readiness is not yet `complete` |
+
+Counters describe engine registrations and overlap intentionally. Fetch completion observes the final
+response's original body source, so unread queued bytes do not keep a completed transfer pending.
+Operations are keyed by their GC cell and hold a weak document reference. Completion, cancellation
+and finalization remove registrations without retaining resources or documents. Changes take O(1)
+bookkeeping; snapshots aggregate the attached documents without walking DOM or layout trees.
+
+`pending: false` covers tracked work at that boundary. It does not mean a committed recording has
+reached the browser. Combine it with lifecycle and frame events and a bounded quiet period. It does
+not cover future timers, input, worker activity, animation or video frames. An ongoing animation-frame
+callback loop remains pending. These signals do not promise permanent visual quiescence.
+
## Sandboxing and overhead
Each helper opens its own file before installing its sandbox. Linux retains the open descriptor;
macOS grants write access to that exact file. Sandboxes remain enabled. The directory must be
-absolute and files must be regular files. Symlinks are rejected.
+absolute and files must be regular files. Symlinks are rejected. The macOS ProcessReaper is a system-library-only watchdog without an engine
+event loop and does not participate in stats logging.
Logging disabled leaves no logger, sampling timer or pending-work state. Hooks check a
constant-initialized thread-local pointer before collecting statistics. Logging enabled adds JSON
diff --git a/Libraries/LibWeb/CMakeLists.txt b/Libraries/LibWeb/CMakeLists.txt
index 8714c155d6e..896c6fbd02c 100644
--- a/Libraries/LibWeb/CMakeLists.txt
+++ b/Libraries/LibWeb/CMakeLists.txt
@@ -788,6 +788,7 @@ set(SOURCES
Page/MiddleButtonScrollHandler.cpp
Page/Page.cpp
Page/PageCursor.cpp
+ Page/RenderingStats.cpp
Page/ScreenWakeLockHandle.cpp
Painting/Blending.cpp
Painting/BoxModelMetrics.cpp
diff --git a/Libraries/LibWeb/CSS/FontComputer.cpp b/Libraries/LibWeb/CSS/FontComputer.cpp
index e4c8ae16fb4..614f5f2c5b3 100644
--- a/Libraries/LibWeb/CSS/FontComputer.cpp
+++ b/Libraries/LibWeb/CSS/FontComputer.cpp
@@ -30,6 +30,7 @@
#include <LibWeb/Layout/RenderDocument.h>
#include <LibWeb/MimeSniff/Resource.h>
#include <LibWeb/Page/Page.h>
+#include <LibWeb/Page/RenderingStats.h>
#include <LibWeb/Platform/FontPlugin.h>
namespace Web::CSS {
@@ -461,8 +462,10 @@ void FontComputer::record_font_input_changes(ReadonlySpan<Utf16FlyString> family
auto& style_engine = document().style_computer().style_engine();
if (style_engine.may_have_deferred_geometry_transaction())
document().flush_deferred_style_change_event();
- if (!style_engine.has_recorded_input())
+ if (!style_engine.has_recorded_input()) {
+ set_rendering_pending(document(), RenderingPendingReason::NeedsRenderingUpdate, 1);
document().page().client().request_frame();
+ }
StyleEngineFFI::style_engine_record_font_input_changes(style_engine.host(), family_name_lengths, family_name_units, font_list_addresses);
}
diff --git a/Libraries/LibWeb/CSS/FontFace.cpp b/Libraries/LibWeb/CSS/FontFace.cpp
index 6baf4939aea..3184a3a4965 100644
--- a/Libraries/LibWeb/CSS/FontFace.cpp
+++ b/Libraries/LibWeb/CSS/FontFace.cpp
@@ -320,6 +320,7 @@ GC::Ref<FontFace> FontFaceState::create_for_constructor(JS::Object& relevant_glo
// 2. Append font face to the FontFaceSet’s [[LoadingFonts]] list.
font_face_set->loading_fonts().append(font_face);
+ font_face_set->did_change_loading_fonts();
}
// 3. Asynchronously, attempt to parse the data in it as a font.
@@ -352,6 +353,7 @@ GC::Ref<FontFace> FontFaceState::create_for_constructor(JS::Object& relevant_glo
// 2. Remove font face from the FontFaceSet’s [[LoadingFonts]] list. If font was the last item in
// that list (and so the list is now empty), switch the FontFaceSet to loaded.
font_face_set->loading_fonts().remove_all_matching([font](auto const& entry) { return entry == font; });
+ font_face_set->did_change_loading_fonts();
if (font_face_set->loading_fonts().is_empty())
font_face_set->switch_to_loaded();
}
@@ -377,6 +379,7 @@ GC::Ref<FontFace> FontFaceState::create_for_constructor(JS::Object& relevant_glo
// 2. Remove font face from the FontFaceSet’s [[LoadingFonts]] list. If font was the last item in
// that list (and so the list is now empty), switch the FontFaceSet to loaded.
font_face_set->loading_fonts().remove_all_matching([font](auto const& entry) { return entry == font; });
+ font_face_set->did_change_loading_fonts();
if (font_face_set->loading_fonts().is_empty())
font_face_set->switch_to_loaded();
}
@@ -914,6 +917,7 @@ void FontFaceState::load_for_style()
if (font_face_set->loading_fonts().is_empty())
font_face_set->switch_to_loading();
font_face_set->loading_fonts().append(*this);
+ font_face_set->did_change_loading_fonts();
}
}
@@ -979,6 +983,7 @@ void FontFaceState::did_load(RefPtr<Gfx::Typeface const> maybe_typeface)
// 2. Remove font face from the FontFaceSet’s [[LoadingFonts]] list. If font was the last item
// in that list (and so the list is now empty), switch the FontFaceSet to loaded.
font_face_set->loading_fonts().remove_all_matching([this](auto const& entry) { return entry == NonnullRefPtr<FontFaceState> { *this }; });
+ font_face_set->did_change_loading_fonts();
if (font_face_set->loading_fonts().is_empty())
font_face_set->switch_to_loaded();
}
@@ -1004,6 +1009,7 @@ void FontFaceState::did_load(RefPtr<Gfx::Typeface const> maybe_typeface)
// 2. Remove font face from the FontFaceSet’s [[LoadingFonts]] list. If font was the last item
// in that list (and so the list is now empty), switch the FontFaceSet to loaded.
font_face_set->loading_fonts().remove_all_matching([this](auto const& entry) { return entry == NonnullRefPtr<FontFaceState> { *this }; });
+ font_face_set->did_change_loading_fonts();
if (font_face_set->loading_fonts().is_empty())
font_face_set->switch_to_loaded();
}
diff --git a/Libraries/LibWeb/CSS/FontFaceSet.cpp b/Libraries/LibWeb/CSS/FontFaceSet.cpp
index c3ff6601630..88bc5bd125b 100644
--- a/Libraries/LibWeb/CSS/FontFaceSet.cpp
+++ b/Libraries/LibWeb/CSS/FontFaceSet.cpp
@@ -33,6 +33,7 @@
#include <LibWeb/HTML/Scripting/TemporaryExecutionContext.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/HighResolutionTime/TimeOrigin.h>
+#include <LibWeb/Page/RenderingStats.h>
#include <LibWeb/Platform/EventLoopPlugin.h>
#include <LibWeb/WebIDL/Promise.h>
@@ -48,6 +49,16 @@ GC::Ref<FontFaceSet> FontFaceSet::create(HTML::EnvironmentSettingsObject& enviro
return font_face_set;
}
+void FontFaceSet::record_loading_fonts()
+{
+ if (!Core::StatsLog::the())
+ return;
+ auto* window = HTML::window_from_global_object(relevant_settings_object().global_object());
+ if (!window || window->associated_document().fonts().ptr() != this)
+ return;
+ set_rendering_pending(window->associated_document(), RenderingPendingReason::FontLoads, m_loading_fonts.size());
+}
+
FontFaceSet::FontFaceSet(HTML::EnvironmentSettingsObject& environment)
: DOM::EventTarget()
, m_environment(environment)
@@ -113,6 +124,7 @@ void FontFaceSet::add_css_connected_font(NonnullRefPtr<FontFaceState> face)
// 2. Append font to the FontFaceSet’s [[LoadingFonts]] list.
m_loading_fonts.append(*face);
+ did_change_loading_fonts();
}
}
@@ -217,6 +229,7 @@ bool FontFaceSet::remove_font_face(NonnullRefPtr<FontFaceState> face, AllowCSSCo
// 4. If font is present in the FontFaceSet’s [[LoadingFonts]] list, remove it.
// If font was the last item in that list (and so the list is now empty), switch the FontFaceSet to loaded.
bool was_in_loading_fonts = m_loading_fonts.remove_all_matching([face](auto const& entry) { return entry == face; });
+ did_change_loading_fonts();
if (was_in_loading_fonts && m_loading_fonts.is_empty())
switch_to_loaded();
@@ -246,6 +259,7 @@ void FontFaceSet::clear()
// then switch the FontFaceSet to loaded.
if (!m_loading_fonts.is_empty()) {
m_loading_fonts.clear();
+ did_change_loading_fonts();
switch_to_loaded();
}
}
diff --git a/Libraries/LibWeb/CSS/FontFaceSet.h b/Libraries/LibWeb/CSS/FontFaceSet.h
index fda6e362126..8267e2a34b4 100644
--- a/Libraries/LibWeb/CSS/FontFaceSet.h
+++ b/Libraries/LibWeb/CSS/FontFaceSet.h
@@ -8,6 +8,7 @@
#pragma once
#include <AK/Utf16String.h>
+#include <LibCore/StatsLog.h>
#include <LibJS/Runtime/Set.h>
#include <LibJS/Runtime/Value.h>
#include <LibWeb/Bindings/FontFaceSet.h>
@@ -58,6 +59,11 @@ public:
Vector<NonnullRefPtr<FontFaceState>>& loading_fonts() { return m_loading_fonts; }
Vector<NonnullRefPtr<FontFaceState>>& loaded_fonts() { return m_loaded_fonts; }
Vector<NonnullRefPtr<FontFaceState>>& failed_fonts() { return m_failed_fonts; }
+ void did_change_loading_fonts()
+ {
+ if (Core::StatsLog::the())
+ record_loading_fonts();
+ }
GC::Ref<WebIDL::Promise> ready();
HTML::EnvironmentSettingsObject& relevant_settings_object() const { return *m_environment; }
@@ -70,6 +76,8 @@ public:
void switch_to_loaded();
private:
+ void record_loading_fonts();
+
enum class AllowCSSConnected {
No,
Yes,
diff --git a/Libraries/LibWeb/CSS/StyleComputer.cpp b/Libraries/LibWeb/CSS/StyleComputer.cpp
index 38053160dca..08e9e93f12e 100644
--- a/Libraries/LibWeb/CSS/StyleComputer.cpp
+++ b/Libraries/LibWeb/CSS/StyleComputer.cpp
@@ -100,6 +100,7 @@
#include <LibWeb/Layout/Node.h>
#include <LibWeb/Namespace.h>
#include <LibWeb/Page/Page.h>
+#include <LibWeb/Page/RenderingStats.h>
#include <LibWeb/Platform/FontPlugin.h>
#include <LibWeb/SVG/SVGElement.h>
#include <LibWeb/StyleValueRustFFI.h>
@@ -1299,6 +1300,7 @@ RefPtr<ComputedStyleWorkingSet> StyleComputer::start_needed_transitions(Layout::
if (!newly_started_transition_effects.is_empty()) {
// NB: Construction does not invalidate animated style because the effects were just evaluated. Request the
// first animation frame directly so timeline updates can schedule subsequent animated style updates.
+ set_rendering_pending(*m_document, RenderingPendingReason::NeedsRenderingUpdate, 1);
m_document->page().client().request_frame();
if (!had_pending_animated_style_update)
m_document->clear_needs_animated_style_update();
diff --git a/Libraries/LibWeb/CSS/StyleEngineBridge.cpp b/Libraries/LibWeb/CSS/StyleEngineBridge.cpp
index 9246afebc98..2c1835f6c10 100644
--- a/Libraries/LibWeb/CSS/StyleEngineBridge.cpp
+++ b/Libraries/LibWeb/CSS/StyleEngineBridge.cpp
@@ -22,6 +22,7 @@
#include <LibWeb/DOM/ShadowRoot.h>
#include <LibWeb/HTML/Scripting/Environments.h>
#include <LibWeb/Page/Page.h>
+#include <LibWeb/Page/RenderingStats.h>
#include <LibWeb/StyleValueRustFFI.h>
namespace Web::CSS {
@@ -266,6 +267,7 @@ static void request_frame_for_first_recorded_input(StyleEngine const& style_engi
{
if (style_engine.has_recorded_input() || !style_computer)
return;
+ set_rendering_pending(style_computer->document(), RenderingPendingReason::NeedsRenderingUpdate, 1);
style_computer->document().page().client().request_frame();
}
diff --git a/Libraries/LibWeb/DOM/Document.cpp b/Libraries/LibWeb/DOM/Document.cpp
index a0dd302b2a3..982164986cb 100644
--- a/Libraries/LibWeb/DOM/Document.cpp
+++ b/Libraries/LibWeb/DOM/Document.cpp
@@ -224,6 +224,7 @@
#include <LibWeb/NavigationTiming/PerformanceNavigationTiming.h>
#include <LibWeb/Page/EventHandler.h>
#include <LibWeb/Page/Page.h>
+#include <LibWeb/Page/RenderingStats.h>
#include <LibWeb/Painting/BoxViews.h>
#include <LibWeb/Painting/ChromeWidget.h>
#include <LibWeb/Painting/CompositorAnimationEffectState.h>
@@ -2826,6 +2827,7 @@ void Document::throttled_animation_visibility_changed()
return;
}
flush_throttled_animation_style_update();
+ set_rendering_pending(*this, RenderingPendingReason::NeedsRenderingUpdate, 1);
page().client().request_frame();
}
@@ -2841,6 +2843,7 @@ void Document::set_needs_animated_style_update(Animations::KeyframeEffect& effec
if (navigable && navigable->has_inclusive_ancestor_with_visibility_hidden())
return;
+ set_rendering_pending(*this, RenderingPendingReason::NeedsRenderingUpdate, 1);
page().client().request_frame();
}
@@ -5041,9 +5044,12 @@ void Document::update_readiness(HTML::DocumentReadyState readiness_value)
// 2. Set document's current document readiness to readinessValue.
m_readiness = readiness_value;
+ set_rendering_pending(*this, RenderingPendingReason::DocumentLoads, readiness_value != HTML::DocumentReadyState::Complete);
- if (readiness_value != HTML::DocumentReadyState::Loading)
+ if (readiness_value != HTML::DocumentReadyState::Loading) {
+ set_rendering_pending(*this, RenderingPendingReason::NeedsRenderingUpdate, 1);
page().client().request_frame();
+ }
// 3. If document is associated with an HTML parser, then:
if (m_parser) {
@@ -5472,6 +5478,7 @@ void Document::update_the_visibility_state(HTML::VisibilityState visibility_stat
// 2. Set document's visibility state to visibilityState.
m_visibility_state = visibility_state;
+ rendering_pending_document_changed(*this);
// FIXME: 3. Queue a new VisibilityStateEntry whose visibility state is visibilityState and whose timestamp is the current
// high resolution time given document's relevant global object.
@@ -5500,6 +5507,7 @@ void Document::update_the_visibility_state(HTML::VisibilityState visibility_stat
if (m_visibility_state == HTML::VisibilityState::Visible) {
flush_throttled_animation_style_update();
+ set_rendering_pending(*this, RenderingPendingReason::NeedsRenderingUpdate, 1);
page().client().request_frame();
}
}
@@ -5875,6 +5883,7 @@ void Document::unregister_svg_use_element(Badge<SVG::SVGUseElement>, SVG::SVGUse
void Document::increment_number_of_things_delaying_the_load_event(Badge<DocumentLoadEventDelayer>)
{
++m_number_of_things_delaying_the_load_event;
+ set_rendering_pending(*this, RenderingPendingReason::LoadEventDelayers, m_number_of_things_delaying_the_load_event);
page().client().page_did_update_resource_count(m_number_of_things_delaying_the_load_event);
// A newly added load-event delayer can make this document's container wait again, including when that container
@@ -5888,6 +5897,7 @@ void Document::decrement_number_of_things_delaying_the_load_event(Badge<Document
{
VERIFY(m_number_of_things_delaying_the_load_event);
--m_number_of_things_delaying_the_load_event;
+ set_rendering_pending(*this, RenderingPendingReason::LoadEventDelayers, m_number_of_things_delaying_the_load_event);
page().client().page_did_update_resource_count(m_number_of_things_delaying_the_load_event);
schedule_html_parser_end_check();
@@ -5896,6 +5906,8 @@ void Document::decrement_number_of_things_delaying_the_load_event(Badge<Document
void Document::increment_number_of_pending_style_sheet_requests(Badge<DocumentLoadEventDelayer>)
{
++m_number_of_pending_style_sheet_requests;
+ set_rendering_pending(*this, RenderingPendingReason::StyleSheetLoads, m_number_of_pending_style_sheet_requests + m_pending_css_import_rules.size());
+ set_rendering_pending(*this, RenderingPendingReason::NeedsRenderingUpdate, 1);
page().client().request_frame();
}
@@ -5903,6 +5915,8 @@ void Document::decrement_number_of_pending_style_sheet_requests(Badge<DocumentLo
{
VERIFY(m_number_of_pending_style_sheet_requests);
--m_number_of_pending_style_sheet_requests;
+ set_rendering_pending(*this, RenderingPendingReason::StyleSheetLoads, m_number_of_pending_style_sheet_requests + m_pending_css_import_rules.size());
+ set_rendering_pending(*this, RenderingPendingReason::NeedsRenderingUpdate, 1);
page().client().request_frame();
}
@@ -6409,6 +6423,8 @@ void Document::destroy()
// AD-HOC: Mark this document as destroyed so we can remove tasks from the queue that will never be able to run.
m_has_been_destroyed = true;
+ rendering_pending_document_changed(*this);
+ rendering_pending_document_changed(*this);
for (auto& observer : m_resize_observers) {
if (observer)
observer->document_was_destroyed({});
@@ -7047,6 +7063,7 @@ void Document::set_initial_visibility_state(HTML::VisibilityState visibility_sta
{
// 1. Set document's visibility state to visibility state.
m_visibility_state = visibility_state;
+ rendering_pending_document_changed(*this);
// The Window's timers follow the document's visibility from here on (see
// WindowOrWorkerGlobalScopeMixin::document_visibility_state_changed()).
if (auto window = this->window(); window && &window->associated_document() == this)
@@ -8286,6 +8303,7 @@ void Document::service_compositor_animation_wakeup(double timestamp)
paint_state().republish_visual_animations(read, *this);
}
++m_style_invalidation_counters.animation_frame_pump_requests;
+ set_rendering_pending(*this, RenderingPendingReason::NeedsRenderingUpdate, 1);
page().client().request_frame();
}
}
@@ -9014,6 +9032,7 @@ void Document::update_compositor_animations(Layout::BegunRead const& read)
if (!m_compositor_animation_observation_timer) {
m_compositor_animation_observation_timer = Core::Timer::create_single_shot(AK::Duration::from_milliseconds(100), GC::weak_callback(*this, [](auto& document) {
++document.m_style_invalidation_counters.animation_frame_pump_requests;
+ set_rendering_pending(document, RenderingPendingReason::NeedsRenderingUpdate, 1);
document.page().client().request_frame();
document.m_compositor_animation_observation_timer->start();
}));
@@ -9183,6 +9202,7 @@ void Document::update_animations_and_send_events(double timestamp)
}
}
++m_style_invalidation_counters.animation_frame_pump_requests;
+ set_rendering_pending(*this, RenderingPendingReason::NeedsRenderingUpdate, 1);
page().client().request_frame();
break;
}
@@ -10331,6 +10351,7 @@ void Document::remove_render_blocking_element(GC::Ref<Element> element)
container->set_needs_repaint(InvalidateDisplayList::PaintCommandsAndHitTestList);
}
+ set_rendering_pending(*this, RenderingPendingReason::NeedsRenderingUpdate, 1);
page().client().request_frame();
}
@@ -10370,6 +10391,7 @@ void Document::run_fullscreen_steps()
void Document::append_pending_fullscreen_change(PendingFullscreenEvent::Type type, GC::Ref<Element> element, Fullscreen::RequestType request_type)
{
m_pending_fullscreen_events.append(PendingFullscreenEvent { type, element, request_type });
+ set_rendering_pending(*this, RenderingPendingReason::NeedsRenderingUpdate, 1);
page().client().request_frame();
}
@@ -10855,6 +10877,8 @@ void Document::set_navigable(GC::Ptr<HTML::LocalNavigable> navigable)
m_navigable = navigable.ptr();
invalidate_full_activity();
HTML::main_thread_event_loop().document_navigable_did_change({});
+ rendering_pending_document_changed(*this);
+ rendering_pending_document_changed(*this);
if (previous_page)
previous_page->update_needs_beforeunload_check();
@@ -10878,14 +10902,23 @@ void Document::set_needs_repaint(InvalidateDisplayList should_invalidate_display
request_frame_for_pending_repaint();
}
+RenderingStats& Document::ensure_rendering_stats() const
+{
+ if (!m_rendering_stats)
+ m_rendering_stats = make<RenderingStats>();
+ return *m_rendering_stats;
+}
+
void Document::request_frame_for_pending_repaint()
{
auto navigable = this->navigable();
if (!navigable) {
// NB: SVG image documents only have a navigable while being rendered. A resource that finishes
// loading between renders must still invalidate the image's cached rendering and notify its clients.
- if (page().client().is_svg_page_client())
+ if (page().client().is_svg_page_client()) {
+ set_rendering_pending(*this, RenderingPendingReason::NeedsRenderingUpdate, 1);
page().client().request_frame();
+ }
return;
}
@@ -10893,6 +10926,7 @@ void Document::request_frame_for_pending_repaint()
// A local root's frames come from its page, whether it is the traversable or another process hosts its parent.
if (navigable->is_local_root()) {
+ set_rendering_pending(*this, RenderingPendingReason::NeedsRenderingUpdate, 1);
page().client().request_frame();
return;
}
@@ -11149,6 +11183,7 @@ void Document::set_caret_hit_test_debug_rect(Optional<CSSPixelRect> rect)
m_caret_hit_test_debug_rect = rect;
set_needs_repaint(InvalidateDisplayList::PaintCommands);
+ set_rendering_pending(*this, RenderingPendingReason::NeedsRenderingUpdate, 1);
page().client().request_frame();
}
@@ -11561,8 +11596,10 @@ void Document::set_rendering_suppression_for_view_transitions(bool value)
m_rendering_suppression_for_view_transitions = value;
- if (!value)
+ if (!value) {
+ set_rendering_pending(*this, RenderingPendingReason::NeedsRenderingUpdate, 1);
page().client().request_frame();
+ }
}
// https://drafts.csswg.org/css-view-transitions-1/#view-transition-page-visibility-change-steps
@@ -12010,13 +12047,17 @@ Utf16View to_string(PartialRelayoutEscapeReason reason)
void Document::add_pending_css_import_rule(Badge<CSS::StyleSheetImport>, NonnullRefPtr<CSS::StyleSheetImport> rule)
{
m_pending_css_import_rules.set(rule);
+ set_rendering_pending(*this, RenderingPendingReason::StyleSheetLoads, m_number_of_pending_style_sheet_requests + m_pending_css_import_rules.size());
}
void Document::remove_pending_css_import_rule(Badge<CSS::StyleSheetImport>, NonnullRefPtr<CSS::StyleSheetImport> rule)
{
m_pending_css_import_rules.remove(rule);
- if (m_pending_css_import_rules.is_empty())
+ set_rendering_pending(*this, RenderingPendingReason::StyleSheetLoads, m_number_of_pending_style_sheet_requests + m_pending_css_import_rules.size());
+ if (m_pending_css_import_rules.is_empty()) {
+ set_rendering_pending(*this, RenderingPendingReason::NeedsRenderingUpdate, 1);
page().client().request_frame();
+ }
}
void Document::exit_pointer_lock()
diff --git a/Libraries/LibWeb/DOM/Document.h b/Libraries/LibWeb/DOM/Document.h
index 0393b6d6a52..f8acd5439ca 100644
--- a/Libraries/LibWeb/DOM/Document.h
+++ b/Libraries/LibWeb/DOM/Document.h
@@ -76,6 +76,12 @@
#include <LibWebCommon/HTML/UserNavigationInvolvement.h>
#include <LibWebCommon/HTML/VisibilityState.h>
+namespace Web {
+
+struct RenderingStats;
+
+}
+
namespace Web::Compositor {
struct FlightPresentation;
@@ -1516,6 +1522,9 @@ public:
void set_caret_hit_test_debug_rect(Optional<CSSPixelRect>);
+ RenderingStats* rendering_stats() const { return m_rendering_stats.ptr(); }
+ RenderingStats& ensure_rendering_stats() const;
+
void set_needs_to_record_display_list();
void set_needs_to_record_display_list_keeping_hit_test_display_list();
@@ -1823,6 +1832,7 @@ private:
RefPtr<Layout::NodeArena> m_layout_node_arena;
NonnullOwnPtr<CommitMessages> m_commit_messages;
OwnPtr<Painting::DocumentPaintState> m_paint_state;
+ mutable OwnPtr<RenderingStats> m_rendering_stats;
NonnullRefPtr<Painting::ChromeWidgetRegistry> m_chrome_widget_registry;
GC::Ptr<Node> m_hovered_node;
diff --git a/Libraries/LibWeb/DOM/EventTarget.cpp b/Libraries/LibWeb/DOM/EventTarget.cpp
index 5d5ac566923..81f1d395193 100644
--- a/Libraries/LibWeb/DOM/EventTarget.cpp
+++ b/Libraries/LibWeb/DOM/EventTarget.cpp
@@ -54,6 +54,7 @@
#include <LibWeb/HTML/WindowOrWorkerGlobalScope.h>
#include <LibWeb/HighResolutionTime/TimeOrigin.h>
#include <LibWeb/Page/Page.h>
+#include <LibWeb/Page/RenderingStats.h>
#include <LibWeb/UIEvents/EventNames.h>
#include <LibWeb/UIEvents/KeyboardEvent.h>
#include <LibWeb/UIEvents/PointerEvent.h>
@@ -333,12 +334,16 @@ static void wake_animation_frame_pump_for_animation_event_listener(EventTarget&
return;
if (auto* window = as_if<HTML::Window>(event_target)) {
+ if (Core::StatsLog::the())
+ set_rendering_pending(window->associated_document(), RenderingPendingReason::NeedsRenderingUpdate, 1);
window->associated_document().page().client().request_frame();
return;
}
- if (auto* node = as_if<Node>(event_target))
+ if (auto* node = as_if<Node>(event_target)) {
+ set_rendering_pending(node->document(), RenderingPendingReason::NeedsRenderingUpdate, 1);
node->document().page().client().request_frame();
+ }
}
static void prepare_to_observe_css_animation_events(EventTarget& event_target, DOMEventListener const& listener)
diff --git a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp b/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp
index da067c430b7..730a28c798d 100644
--- a/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp
+++ b/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp
@@ -62,6 +62,7 @@
#include <LibWeb/Loader/ResourceLoader.h>
#include <LibWeb/MixedContent/AbstractOperations.h>
#include <LibWeb/Page/Page.h>
+#include <LibWeb/Page/RenderingStats.h>
#include <LibWeb/Platform/EventLoopPlugin.h>
#include <LibWeb/ReferrerPolicy/AbstractOperations.h>
#include <LibWeb/ResourceTiming/PerformanceResourceTiming.h>
@@ -366,6 +367,9 @@ GC::Ref<Infrastructure::FetchController> fetch(JS::Realm& realm, Infrastructure:
request.client()->fetch_group().append(record);
}
+ if (Core::StatsLog::the() && client_window && request.is_subresource_request())
+ begin_rendering_pending_operation(fetch_params->controller().ptr(), client_window->associated_document(), RenderingPendingReason::ResourceFetchesInFlight);
+
// 15. Run main fetch given fetchParams.
(void)main_fetch(realm, fetch_params);
@@ -903,6 +907,7 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams const
auto process_response_end_of_body_task = GC::create_function(GC::Heap::the(), [&fetch_params, &response] {
// 1. Set fetchParams’s request’s done flag.
fetch_params.request()->set_done(true);
+ end_rendering_pending_operation(fetch_params.controller().ptr());
// 2. If fetchParams’s process response end-of-body is non-null, then run fetchParams’s process response
// end-of-body given response.
@@ -935,6 +940,9 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams const
// 5. Let internalResponse be response, if response is a network error; otherwise response’s internal response.
auto internal_response = response.is_network_error() ? GC::Ref { response } : response.unsafe_response();
+ if (Core::StatsLog::the() && internal_response->body())
+ track_rendering_pending_stream(fetch_params.controller().ptr(), *internal_response->body()->stream());
+
auto algorithms = fetch_params.algorithms();
// AD-HOC: A parallel-queue task destination with a process-response-consume-body algorithm is a sync XHR send()
@@ -1007,9 +1015,11 @@ void fetch_response_handover(JS::Realm& realm, Infrastructure::FetchParams const
// 2. Let processBodyError be this step: run fetchParams’s process response consume body given response and
// failure.
- auto process_body_error = GC::create_function(GC::Heap::the(), [algorithms, &response, setup_report_timing_steps](JS::Value) {
+ auto process_body_error = GC::create_function(GC::Heap::the(), [algorithms, &response, controller = fetch_params.controller(), setup_report_timing_steps](JS::Value) {
// AD-HOC: See comment on setup_report_timing_steps above.
setup_report_timing_steps();
+ // NB: A failed read does not always close or error the body's stream, which would otherwise end this.
+ end_rendering_pending_operation(controller.ptr());
(algorithms->process_response_consume_body())(response, Infrastructure::FetchAlgorithms::ConsumeBodyFailureTag {});
});
diff --git a/Libraries/LibWeb/Fetch/Infrastructure/FetchController.cpp b/Libraries/LibWeb/Fetch/Infrastructure/FetchController.cpp
index 90302c67923..cfb19997d66 100644
--- a/Libraries/LibWeb/Fetch/Infrastructure/FetchController.cpp
+++ b/Libraries/LibWeb/Fetch/Infrastructure/FetchController.cpp
@@ -14,6 +14,7 @@
#include <LibWeb/Fetch/Infrastructure/FetchParams.h>
#include <LibWeb/HTML/EventLoop/EventLoop.h>
#include <LibWeb/HTML/StructuredSerialize.h>
+#include <LibWeb/Page/RenderingStats.h>
#include <LibWeb/WebIDL/DOMException.h>
namespace Web::Fetch::Infrastructure {
@@ -22,6 +23,13 @@ GC_DEFINE_ALLOCATOR(FetchController);
FetchController::FetchController() = default;
+void FetchController::finalize()
+{
+ // A discarded response can leave an ongoing controller without a stop or end-of-body task.
+ end_rendering_pending_operation(this);
+ Base::finalize();
+}
+
GC::Ref<FetchController> FetchController::create()
{
return GC::Heap::the().allocate<FetchController>();
@@ -171,6 +179,7 @@ void FetchController::stop_fetch()
// https://fetch.spec.whatwg.org/#concept-http-network-fetch
void FetchController::stop_request()
{
+ end_rendering_pending_operation(this);
VERIFY(m_state != State::Ongoing);
if (m_pending_request) {
m_pending_request->stop();
diff --git a/Libraries/LibWeb/Fetch/Infrastructure/FetchController.h b/Libraries/LibWeb/Fetch/Infrastructure/FetchController.h
index c38ed29bb74..cdae1d5617e 100644
--- a/Libraries/LibWeb/Fetch/Infrastructure/FetchController.h
+++ b/Libraries/LibWeb/Fetch/Infrastructure/FetchController.h
@@ -87,6 +87,7 @@ private:
FetchController();
virtual void visit_edges(JS::Cell::Visitor&) override;
+ virtual void finalize() override;
// https://fetch.spec.whatwg.org/#fetch-controller-state
// state (default "ongoing")
diff --git a/Libraries/LibWeb/HTML/AnimationFrameCallbackDriver.h b/Libraries/LibWeb/HTML/AnimationFrameCallbackDriver.h
index 0d09ec11d1e..0a6f48c9f79 100644
--- a/Libraries/LibWeb/HTML/AnimationFrameCallbackDriver.h
+++ b/Libraries/LibWeb/HTML/AnimationFrameCallbackDriver.h
@@ -24,6 +24,7 @@ class WEB_API AnimationFrameCallbackDriver final : public JS::Cell {
using Callback = GC::Ref<GC::Function<void(double)>>;
public:
+ size_t callback_count() const { return m_callbacks.size(); }
[[nodiscard]] static GC::Ref<AnimationFrameCallbackDriver> create();
[[nodiscard]] WebIDL::UnsignedLong add(Callback handler);
diff --git a/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp b/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp
index eaa0a333f96..6519c60d406 100644
--- a/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp
+++ b/Libraries/LibWeb/HTML/EventLoop/EventLoop.cpp
@@ -42,6 +42,7 @@
#include <LibWeb/Layout/TreeBuilderRustFFI.h>
#include <LibWeb/Page/EventHandler.h>
#include <LibWeb/Page/Page.h>
+#include <LibWeb/Page/RenderingStats.h>
#include <LibWeb/Painting/BoxViews.h>
#include <LibWeb/Painting/DocumentPaintState.h>
#include <LibWeb/Platform/EventLoopPlugin.h>
@@ -164,6 +165,13 @@ void EventLoop::process()
if (execution_paused())
return;
+ if (Core::StatsLog::the())
+ begin_rendering_pending_task();
+ ScopeGuard pending_task = [] {
+ if (Core::StatsLog::the())
+ end_rendering_pending_task();
+ };
+
// 1. Let oldestTask and taskStartTime be null.
GC::Ptr<Task> oldest_task;
[[maybe_unused]] double task_start_time = 0;
@@ -1199,6 +1207,8 @@ void EventLoop::update_the_rendering_after_style_and_layout(Vector<GC::Root<DOM:
// AD-HOC: Script that ran earlier in this rendering update may have spun the event loop and run tasks that
// detached doc from its navigable (e.g. after its iframe was removed).
auto lay_out_first = taken_layout == TakenLayout::UpToDate ? LocalNavigable::LayOutFirst::Yes : LocalNavigable::LayOutFirst::No;
+ if (Core::StatsLog::the() && navigable && !navigable->needs_repaint())
+ did_update_rendering(*doc);
if (!navigable || !navigable->paint_next_frame_if_needed(DOM::UpdateLayoutReason::HTMLEventLoopRenderingUpdate, lay_out_first))
continue;
++m_rendering_scheduler_counters.paints;
@@ -1570,6 +1580,9 @@ void EventLoop::perform_a_microtask_checkpoint()
// 7. Set the event loop's performing a microtask checkpoint to false.
m_performing_a_microtask_checkpoint = false;
+ if (Core::StatsLog::the())
+ flush_rendering_pending();
+
// FIXME: 8. Record timing info for microtask checkpoint.
}
@@ -1621,6 +1634,7 @@ void EventLoop::add_stats(JsonObject& values) const
void EventLoop::unregister_document(Badge<DOM::Document>, DOM::Document& document)
{
+ forget_rendering_stats(document);
bool did_remove = m_documents.remove_first_matching([&](auto& entry) { return entry.ptr().ptr() == &document; });
VERIFY(did_remove);
}
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.cpp b/Libraries/LibWeb/HTML/LocalNavigable.cpp
index 0a70b36a175..4f2d7d4ef46 100644
--- a/Libraries/LibWeb/HTML/LocalNavigable.cpp
+++ b/Libraries/LibWeb/HTML/LocalNavigable.cpp
@@ -82,6 +82,7 @@
#include <LibWeb/Layout/Viewport.h>
#include <LibWeb/Loader/GeneratedPagesLoader.h>
#include <LibWeb/Page/Page.h>
+#include <LibWeb/Page/RenderingStats.h>
#include <LibWeb/Painting/BoxViews.h>
#include <LibWeb/Painting/ChromeWidget.h>
#include <LibWeb/Painting/DocumentPaintState.h>
@@ -4654,6 +4655,7 @@ void LocalNavigable::set_viewport_intersection(CSSPixelRect intersection)
if (m_viewport_intersection == intersection)
return;
m_viewport_intersection = intersection;
+ set_rendering_pending_displayed(*this, !intersection.is_empty());
// Intersection observations only run when the document renders, so ask for one.
if (auto document = active_document()) {
@@ -6452,7 +6454,7 @@ void LocalNavigable::repaint_after_compositor_process_reconnect()
page().client().device_pixel_ratio(),
Compositing::WindowResizingInProgress::No);
- m_needs_repaint = true;
+ set_needs_repaint();
m_needs_to_record_display_list = true;
presenter().forget_compositor_display_list();
}
@@ -6595,6 +6597,7 @@ bool LocalNavigable::commit_frame(PaintConfig paint_config)
|| !compositor_display_list_paint_config.has_value()
|| !(compositor_display_list_paint_config.value() == paint_config);
auto sealed = seal_presentation(*document, paint_config, should_record_display_list);
+ set_rendering_pending(*document, RenderingPendingReason::NeedsRenderingUpdate, 0);
if (!should_record_display_list) {
commit_unrecorded_frame(read, *document, move(sealed));
return true;
@@ -6795,6 +6798,12 @@ void LocalNavigable::finish_recording_in_flight(RecordingInFlight& in_flight, La
document->adopt_published_recording(Painting::hit_test_list_read(read, hit_test_list_stands), *in_flight.recording, sealed->published->display_list, [&] { return sealed->published->referenced_resources; });
}
+void LocalNavigable::record_rendering_invalidation()
+{
+ if (auto document = active_document())
+ set_rendering_pending(*document, RenderingPendingReason::NeedsRenderingUpdate, 1);
+}
+
void LocalNavigable::paint_next_frame()
{
if (has_been_destroyed())
diff --git a/Libraries/LibWeb/HTML/LocalNavigable.h b/Libraries/LibWeb/HTML/LocalNavigable.h
index 4073e01c2e0..9b073b01ed0 100644
--- a/Libraries/LibWeb/HTML/LocalNavigable.h
+++ b/Libraries/LibWeb/HTML/LocalNavigable.h
@@ -18,6 +18,7 @@
#include <LibCompositing/Scrolling/ScrollState.h>
#include <LibCompositing/Scrolling/SmoothScrollAnimation.h>
#include <LibCore/Forward.h>
+#include <LibCore/StatsLog.h>
#include <LibGC/RootVector.h>
#include <LibWeb/Bindings/CSS.h>
#include <LibWeb/Bindings/Navigation.h>
@@ -318,8 +319,16 @@ public:
// which gives it back.
Compositor::NavigablePresenter& presenter();
+ bool stats_ancestors_displayed() const { return m_stats_ancestors_displayed; }
+ bool update_stats_ancestors_displayed(bool displayed) { return exchange(m_stats_ancestors_displayed, displayed) != displayed; }
+
bool needs_repaint() const { return m_needs_repaint; }
- void set_needs_repaint() { m_needs_repaint = true; }
+ void set_needs_repaint()
+ {
+ m_needs_repaint = true;
+ if (Core::StatsLog::the())
+ record_rendering_invalidation();
+ }
bool needs_to_record_display_list() const { return m_needs_to_record_display_list; }
void set_needs_to_record_display_list() { m_needs_to_record_display_list = true; }
void repaint_after_compositor_process_reconnect();
@@ -423,6 +432,8 @@ protected:
Variant<Empty, Traversal, Utf16String> m_ongoing_navigation;
private:
+ void record_rendering_invalidation();
+
// A rendering update's recording that flies beside the event loop, with what its frame is finished with.
struct RecordingInFlight;
@@ -580,6 +591,7 @@ private:
Vector<Utf16String> m_queued_javascript_url_navigations;
bool m_is_svg_page { false };
+ bool m_stats_ancestors_displayed { false };
bool m_needs_repaint { true };
bool m_needs_to_record_display_list { true };
diff --git a/Libraries/LibWeb/HTML/NavigableContainer.cpp b/Libraries/LibWeb/HTML/NavigableContainer.cpp
index f6c1232f63e..cfa22054254 100644
--- a/Libraries/LibWeb/HTML/NavigableContainer.cpp
+++ b/Libraries/LibWeb/HTML/NavigableContainer.cpp
@@ -31,6 +31,7 @@
#include <LibWeb/Layout/Box.h>
#include <LibWeb/Layout/Node.h>
#include <LibWeb/Page/Page.h>
+#include <LibWeb/Page/RenderingStats.h>
#include <LibWeb/Painting/BoxViews.h>
namespace Web::HTML {
@@ -105,6 +106,7 @@ void NavigableContainer::create_new_child_navigable()
// 9. Set element's content navigable to navigable.
m_content_navigable = navigable;
m_reported_content_navigable_viewport = {};
+ m_reported_stats_displayed = {};
navigable->set_container({}, this);
publish_dom_paint_facts();
@@ -306,6 +308,7 @@ void NavigableContainer::destroy_the_child_navigable()
// 3. Set container's content navigable to null.
m_content_navigable = nullptr;
m_reported_content_navigable_viewport = {};
+ m_reported_stats_displayed = {};
navigable->set_container({}, nullptr);
document().schedule_html_parser_end_check();
publish_dom_paint_facts();
@@ -512,6 +515,15 @@ static CSSPixelRect transform_rect_to_local(Layout::Node const& layout_node, CSS
return { top_left, { bottom_right.x() - top_left.x(), bottom_right.y() - top_left.y() } };
}
+void NavigableContainer::report_stats_displayed(bool displayed)
+{
+ set_rendering_pending_displayed(*m_content_navigable, displayed);
+ if (m_reported_stats_displayed == displayed)
+ return;
+ m_reported_stats_displayed = displayed;
+ document().page().client().page_did_update_frame_stats_displayed(m_content_navigable->id(), displayed);
+}
+
void NavigableContainer::report_content_navigable_viewport_rect(Layout::BegunRead const& read)
{
if (!m_content_navigable)
@@ -522,8 +534,11 @@ void NavigableContainer::report_content_navigable_viewport_rect(Layout::BegunRea
if (!document().layout_is_up_to_date())
return;
auto const* layout_node = this->layout_node(read);
- if (!layout_node || !Painting::is_navigable_container_viewport_paintable(*layout_node))
+ if (!layout_node || !Painting::is_navigable_container_viewport_paintable(*layout_node)) {
+ if (Core::StatsLog::the())
+ report_stats_displayed(false);
return;
+ }
// The content navigable's viewport is the container's content box, which keeps its size under the transforms
// above the container. Those place its origin in the viewport of the local root through the viewports of the
@@ -540,8 +555,11 @@ void NavigableContainer::report_content_navigable_viewport_rect(Layout::BegunRea
// Each container's box is a read of the render state of its own document.
Layout::ForcedReadScope container_read { container->document() };
auto const* container_layout_node = container->layout_node(container_read);
- if (!container_layout_node || !Painting::is_navigable_container_viewport_paintable(*container_layout_node))
+ if (!container_layout_node || !Painting::is_navigable_container_viewport_paintable(*container_layout_node)) {
+ if (Core::StatsLog::the())
+ report_stats_displayed(false);
return;
+ }
// The content box's origin is the origin of the child's viewport, and the transforms above the container
// apply to the child as they do to the container.
auto container_position = Painting::absolute_position(*container_layout_node);
@@ -563,6 +581,12 @@ void NavigableContainer::report_content_navigable_viewport_rect(Layout::BegunRea
for (auto const* container_layout_node : containers.in_reverse())
visible = transform_rect_to_local(*container_layout_node, visible).translated(-Painting::absolute_position(*container_layout_node));
visible.intersect({ {}, content_box.size() });
+ if (Core::StatsLog::the()) {
+ bool displayed = !visible.is_empty() && !document().navigable()->has_inclusive_ancestor_with_visibility_hidden();
+ if (auto const* values = style_group<CSS::ComputedValues::InheritedBoxValues>())
+ displayed &= static_cast<CSS::Visibility>(values->visibility) != CSS::Visibility::Hidden;
+ report_stats_displayed(displayed);
+ }
// The report is in the device pixels the content is laid out in, so a change of zoom level reports again.
auto& page = document().page();
diff --git a/Libraries/LibWeb/HTML/NavigableContainer.h b/Libraries/LibWeb/HTML/NavigableContainer.h
index 76552a0ce7e..ca6ee9df747 100644
--- a/Libraries/LibWeb/HTML/NavigableContainer.h
+++ b/Libraries/LibWeb/HTML/NavigableContainer.h
@@ -55,6 +55,7 @@ public:
// in the viewport of the local root, and tells that navigable the part of it the top-level viewport shows. Both
// are reported whenever they change.
void report_content_navigable_viewport_rect(Layout::BegunRead const& read);
+ bool stats_displayed() const { return m_reported_stats_displayed.value_or(false); }
protected:
NavigableContainer(DOM::Document&, DOM::QualifiedName);
@@ -81,6 +82,9 @@ private:
static void finish_destroying_the_child_navigable(Navigable&);
+ void report_stats_displayed(bool);
+ Optional<bool> m_reported_stats_displayed;
+
bool m_potentially_delays_the_load_event { true };
struct ReportedContentNavigableViewport {
diff --git a/Libraries/LibWeb/HTML/SharedResourceRequest.cpp b/Libraries/LibWeb/HTML/SharedResourceRequest.cpp
index b28e891fb44..6c5a3ae40e7 100644
--- a/Libraries/LibWeb/HTML/SharedResourceRequest.cpp
+++ b/Libraries/LibWeb/HTML/SharedResourceRequest.cpp
@@ -22,6 +22,7 @@
#include <LibWeb/HTML/SharedResourceRequest.h>
#include <LibWeb/Loader/ResourceLoader.h>
#include <LibWeb/Page/Page.h>
+#include <LibWeb/Page/RenderingStats.h>
#include <LibWeb/Platform/ImageCodecPlugin.h>
#include <LibWeb/SVG/SVGDecodedImageData.h>
#include <LibWebCommon/Fetch/Infrastructure/HTTP/Statuses.h>
@@ -56,6 +57,7 @@ SharedResourceRequest::~SharedResourceRequest() = default;
void SharedResourceRequest::finalize()
{
+ end_rendering_pending_operation(this);
Base::finalize();
m_callbacks.clear();
@@ -228,6 +230,7 @@ void SharedResourceRequest::add_callbacks(Function<void()> on_finish, Function<v
void SharedResourceRequest::handle_successful_fetch(URL::URL const& url_string, IsSVGImage is_svg_image, ByteBuffer data, bool image_data_is_cors_cross_origin)
{
+ begin_rendering_pending_operation(this, *m_document, RenderingPendingReason::ImageDecodes);
// AD-HOC: At this point, things gets very ad-hoc.
// FIXME: Bring this closer to spec.
@@ -289,6 +292,7 @@ void SharedResourceRequest::handle_successful_fetch(URL::URL const& url_string,
void SharedResourceRequest::handle_failed_fetch()
{
+ end_rendering_pending_operation(this);
m_state = State::Failed;
m_load_event_delayer.clear();
m_fetch_controller = nullptr;
@@ -306,6 +310,7 @@ void SharedResourceRequest::handle_stopped_fetch()
if (m_state != State::Fetching)
return;
+ end_rendering_pending_operation(this);
m_state = State::Stopped;
remove_from_document();
m_load_event_delayer.clear();
@@ -319,6 +324,7 @@ void SharedResourceRequest::handle_stopped_fetch()
void SharedResourceRequest::handle_successful_resource_load()
{
+ end_rendering_pending_operation(this);
m_state = State::Finished;
m_load_event_delayer.clear();
m_fetch_controller = nullptr;
diff --git a/Libraries/LibWeb/HTML/Window.cpp b/Libraries/LibWeb/HTML/Window.cpp
index 67b2940e85f..ba22e97e2aa 100644
--- a/Libraries/LibWeb/HTML/Window.cpp
+++ b/Libraries/LibWeb/HTML/Window.cpp
@@ -86,6 +86,7 @@
#include <LibWeb/Internals/Internals.h>
#include <LibWeb/Layout/Viewport.h>
#include <LibWeb/Page/Page.h>
+#include <LibWeb/Page/RenderingStats.h>
#include <LibWeb/Painting/BoxViews.h>
#include <LibWeb/Painting/PaintingRustBridge.h>
#include <LibWeb/RequestIdleCallback/IdleDeadline.h>
@@ -294,7 +295,11 @@ void Window::for_each_active(Function<IterationDecision(Window&)> callback)
void run_animation_frame_callbacks(DOM::Document& document, double now)
{
// FIXME: Bring this closer to the spec.
- document.window()->animation_frame_callback_driver().run(now);
+ auto& driver = document.window()->animation_frame_callback_driver();
+ set_rendering_pending(document, RenderingPendingReason::ScheduledAnimationFrameCallbacks, 0);
+ driver.run(now);
+ if (Core::StatsLog::the())
+ set_rendering_pending(document, RenderingPendingReason::ScheduledAnimationFrameCallbacks, driver.callback_count());
}
// NB: A GC cell, so that the window's two idle callback lists trace the handler, and with it the WebIDL callback the
@@ -2130,6 +2135,8 @@ WebIDL::UnsignedLong Window::request_animation_frame(AnimationFrameCallbackHandl
{
// FIXME: Make this fully spec compliant. Currently implements a mix of 'requestAnimationFrame()' and 'run the animation frame callbacks'.
auto handle = animation_frame_callback_driver().add(GC::create_function(GC::Heap::the(), move(callback)));
+ if (Core::StatsLog::the())
+ set_rendering_pending(associated_document(), RenderingPendingReason::ScheduledAnimationFrameCallbacks, animation_frame_callback_driver().callback_count());
page().client().request_frame();
return handle;
}
@@ -2142,8 +2149,11 @@ void Window::cancel_animation_frame(WebIDL::UnsignedLong handle)
// 2. Let callbacks be this's target object's map of animation frame callbacks.
// 3. Remove callbacks[handle].
- if (m_animation_frame_callback_driver)
+ if (m_animation_frame_callback_driver) {
(void)m_animation_frame_callback_driver->remove(handle);
+ if (Core::StatsLog::the())
+ set_rendering_pending(associated_document(), RenderingPendingReason::ScheduledAnimationFrameCallbacks, m_animation_frame_callback_driver->callback_count());
+ }
}
AnimationFrameCallbackDriver& Window::animation_frame_callback_driver()
diff --git a/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp b/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp
index d6deab48bbb..3708c679a7c 100644
--- a/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp
+++ b/Libraries/LibWeb/HTML/WindowOrWorkerGlobalScope.cpp
@@ -64,6 +64,7 @@
#include <LibWeb/Loader/ResourceLoader.h>
#include <LibWeb/NavigationTiming/PerformanceNavigationTiming.h>
#include <LibWeb/Page/Page.h>
+#include <LibWeb/Page/RenderingStats.h>
#include <LibWeb/Painting/PaintingRustBridge.h>
#include <LibWeb/PerformanceTimeline/EntryTypes.h>
#include <LibWeb/PerformanceTimeline/EventNames.h>
@@ -459,6 +460,10 @@ void WindowOrWorkerGlobalScopeMixin::create_image_bitmap_impl(JS::Realm& realm,
image.visit(
// -> Blob
[&](GC::Ref<FileAPI::Blob> blob) {
+ if (Core::StatsLog::the()) {
+ if (auto* window = window_from_global_object(realm.global_object()))
+ begin_rendering_pending_operation(GC::as_cell(p.ptr()), window->associated_document(), RenderingPendingReason::ImageDecodes);
+ }
// Run these step in parallel:
Platform::EventLoopPlugin::the().deferred_invoke(GC::create_function(GC::Heap::the(), [=]() {
// 1. Let imageData be the result of reading image's data. If an error occurs during reading of the
@@ -472,6 +477,8 @@ void WindowOrWorkerGlobalScopeMixin::create_image_bitmap_impl(JS::Realm& realm,
// image (as given by image's type attribute) giving the official type.
auto on_failed_decode = [p = GC::Root(*p)](Error&) {
+ if (Core::StatsLog::the())
+ end_rendering_pending_operation(GC::as_cell(p.ptr()));
// 3. If imageData is not in a supported image file format (e.g., it's not an image at all), or if
// imageData is corrupted in some fatal way such that the image dimensions cannot be obtained
// (e.g., a vector graphic with no natural size), then queue a global task, using the bitmap
@@ -485,6 +492,8 @@ void WindowOrWorkerGlobalScopeMixin::create_image_bitmap_impl(JS::Realm& realm,
};
auto on_successful_decode = [image_bitmap = GC::Root(*image_bitmap), p = GC::Root(*p), sx, sy, sw, sh, options](Web::Platform::DecodedImage& result) -> ErrorOr<void> {
+ if (Core::StatsLog::the())
+ end_rendering_pending_operation(GC::as_cell(p.ptr()));
// 4. Set imageBitmap's bitmap data to imageData, cropped to the source rectangle with formatting.
// If this is an animated image, imageBitmap's bitmap data must only be taken from the default image
// of the animation (the one that the format defines is to be used when animation is not supported
diff --git a/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp b/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp
index d697ec188e7..3b6b03c49e4 100644
--- a/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp
+++ b/Libraries/LibWeb/IntersectionObserver/IntersectionObserver.cpp
@@ -21,6 +21,7 @@
#include <LibWeb/IntersectionObserver/IntersectionObserver.h>
#include <LibWeb/Layout/Viewport.h>
#include <LibWeb/Page/Page.h>
+#include <LibWeb/Page/RenderingStats.h>
#include <LibWeb/Painting/BoxViews.h>
#include <LibWeb/ValueParserRustFFI.h>
#include <LibWeb/WebIDL/AbstractOperations.h>
@@ -220,6 +221,7 @@ void IntersectionObserver::observe(DOM::Element& target)
// AD-HOC: Registering an observation changes whether transforms can remain compositor driven. Bring any pending
// throttled animation state to a point where compositor eligibility can be updated by the requested frame.
target.document().flush_throttled_animation_style_update_for_node(target);
+ set_rendering_pending(*m_document, RenderingPendingReason::NeedsRenderingUpdate, 1);
m_document->page().client().request_frame();
}
diff --git a/Libraries/LibWeb/Page/Page.cpp b/Libraries/LibWeb/Page/Page.cpp
index e91f1be78b1..d355640dfe6 100644
--- a/Libraries/LibWeb/Page/Page.cpp
+++ b/Libraries/LibWeb/Page/Page.cpp
@@ -41,6 +41,7 @@
#include <LibWeb/Layout/Viewport.h>
#include <LibWeb/Loader/ContentBlocker.h>
#include <LibWeb/Page/Page.h>
+#include <LibWeb/Page/RenderingStats.h>
#include <LibWeb/Painting/BoxViews.h>
#include <LibWeb/Painting/PaintFacts.h>
#include <LibWeb/PictureInPicture/PictureInPictureController.h>
@@ -70,6 +71,12 @@ Page::Page(GC::Ref<PageClient> client)
Page::~Page() = default;
+void Page::finalize()
+{
+ forget_rendering_pending(*this);
+ Base::finalize();
+}
+
void Page::acquire_screen_wake_lock()
{
if (m_active_screen_wake_lock_count++ == 0)
diff --git a/Libraries/LibWeb/Page/Page.h b/Libraries/LibWeb/Page/Page.h
index 7f98884da21..af4308f888c 100644
--- a/Libraries/LibWeb/Page/Page.h
+++ b/Libraries/LibWeb/Page/Page.h
@@ -454,6 +454,7 @@ public:
private:
explicit Page(GC::Ref<PageClient>);
virtual void visit_edges(Visitor&) override;
+ virtual void finalize() override;
void update_focused_navigable(GC::Ptr<HTML::Navigable>);
@@ -666,6 +667,7 @@ public:
virtual void page_did_completely_finish_loading([[maybe_unused]] HTML::CrossProcessId navigable_id, DOM::Document const&) { }
virtual void page_did_change_navigable_container_state([[maybe_unused]] HTML::CrossProcessId navigable_id, [[maybe_unused]] HTML::ReplicatedContainerState const& state) { }
virtual void page_did_update_child_frame_viewport(HTML::CrossProcessId, [[maybe_unused]] DevicePixelRect viewport_rect, [[maybe_unused]] DevicePixelRect viewport_intersection) { }
+ virtual void page_did_update_frame_stats_displayed(HTML::CrossProcessId, bool) { }
virtual void page_did_destroy_child_frame(HTML::CrossProcessId) { }
virtual String dump_site_isolation_process_tree_for_testing() { return {}; }
virtual void crash_remote_frame_processes_for_testing() { }
diff --git a/Libraries/LibWeb/Page/RenderingStats.cpp b/Libraries/LibWeb/Page/RenderingStats.cpp
new file mode 100644
index 00000000000..85453c6364d
--- /dev/null
+++ b/Libraries/LibWeb/Page/RenderingStats.cpp
@@ -0,0 +1,297 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <AK/Array.h>
+#include <AK/HashMap.h>
+#include <AK/NeverDestroyed.h>
+#include <LibCore/EventLoop.h>
+#include <LibGC/Weak.h>
+#include <LibJS/Runtime/VM.h>
+#include <LibWeb/Bindings/MainThreadVM.h>
+#include <LibWeb/CSS/StyleComputer.h>
+#include <LibWeb/DOM/Document.h>
+#include <LibWeb/HTML/LocalNavigable.h>
+#include <LibWeb/HTML/NavigableContainer.h>
+#include <LibWeb/Page/Page.h>
+#include <LibWeb/Page/RenderingStats.h>
+#include <LibWeb/Streams/ReadableByteStreamController.h>
+#include <LibWeb/Streams/ReadableStream.h>
+#include <LibWeb/Streams/ReadableStreamDefaultController.h>
+
+namespace Web {
+
+struct PagePendingStats {
+ RenderingPendingCounts last_counts {};
+ HashTable<GC::RawPtr<DOM::Document const>> documents;
+ bool logged { false };
+};
+
+struct PendingOperation {
+ GC::Weak<DOM::Document const> document;
+ RenderingPendingReason reason;
+ GC::RawPtr<Streams::ReadableStream const> stream {};
+};
+
+struct PendingStats {
+ HashMap<GC::RawPtr<Page const>, PagePendingStats> pages;
+ HashMap<GC::RawPtr<GC::Cell const>, PendingOperation> operations;
+ HashMap<GC::RawPtr<Streams::ReadableStream const>, HashTable<GC::RawPtr<GC::Cell const>>> streams;
+ HashTable<GC::RawPtr<Page const>> dirty_pages;
+ bool flush_queued { false };
+ size_t task_depth { 0 };
+};
+
+static thread_local PendingStats* s_pending_stats;
+
+static PendingStats& pending_stats()
+{
+ static thread_local NeverDestroyed<PendingStats> stats;
+ s_pending_stats = &*stats;
+ return *stats;
+}
+
+static void pending_changed(Page const& page)
+{
+ auto& stats = pending_stats();
+ stats.dirty_pages.set(&page);
+ if (stats.flush_queued)
+ return;
+ stats.flush_queued = true;
+ Core::deferred_invoke([] {
+ s_pending_stats->flush_queued = false;
+ // HTML tasks flush after their microtasks. Other engine callbacks flush at the Core event-loop boundary.
+ if (!Bindings::main_thread_vm().has_running_execution_context())
+ flush_rendering_pending();
+ });
+}
+
+static void remove_pending_document(DOM::Document const& document, RenderingStats& stats)
+{
+ auto page = exchange(stats.pending_page, nullptr);
+ if (!page || !s_pending_stats)
+ return;
+ auto it = s_pending_stats->pages.find(page);
+ if (it == s_pending_stats->pages.end())
+ return;
+ it->value.documents.remove(&document);
+ pending_changed(*page);
+}
+
+void Detail::forget_rendering_stats(DOM::Document const& document)
+{
+ if (auto* stats = document.rendering_stats())
+ remove_pending_document(document, *stats);
+}
+
+void Detail::set_rendering_pending(DOM::Document const& document, RenderingPendingReason reason, u64 count)
+{
+ if (!Core::StatsLog::the() || document.is_decoded_svg())
+ return;
+ auto& stats = document.ensure_rendering_stats();
+ auto& previous = stats.pending[to_underlying(reason)];
+ if (previous == count)
+ return;
+ if (auto page = stats.pending_page)
+ pending_changed(*page);
+ previous = count;
+}
+
+void Detail::rendering_pending_document_changed(DOM::Document const& document)
+{
+ if (!Core::StatsLog::the() || document.is_decoded_svg())
+ return;
+ auto& stats = document.ensure_rendering_stats();
+ remove_pending_document(document, stats);
+ auto& pages = pending_stats().pages;
+ auto navigable = document.navigable();
+ if (!navigable || document.has_been_destroyed() || !navigable->active_document_is(document))
+ return;
+ auto& page = document.page();
+ auto& page_stats = pages.ensure(&page);
+ stats.pending_page = &page;
+ page_stats.documents.set(&document);
+ stats.displayed = navigable->is_local_root() || (navigable->container() && navigable->container()->stats_displayed());
+ pending_changed(page);
+ Detail::set_rendering_pending(document, RenderingPendingReason::NeedsRenderingUpdate, 1);
+ Detail::set_rendering_pending(document, RenderingPendingReason::DocumentLoads, document.readiness() != HTML::DocumentReadyState::Complete);
+}
+
+void Detail::set_rendering_pending_displayed(HTML::Navigable const& navigable, bool displayed)
+{
+ auto const* local = as_if<HTML::LocalNavigable>(navigable);
+ if (!local)
+ return;
+ if (auto document = local->active_document()) {
+ auto& stats = document->ensure_rendering_stats();
+ if (exchange(stats.displayed, displayed) != displayed && stats.pending_page)
+ pending_changed(*stats.pending_page);
+ }
+}
+
+void Detail::set_rendering_pending_ancestors_displayed(HTML::LocalNavigable& navigable, bool displayed)
+{
+ if (navigable.update_stats_ancestors_displayed(displayed))
+ pending_changed(navigable.page());
+}
+
+void Detail::forget_rendering_pending(Page const& page)
+{
+ if (!s_pending_stats)
+ return;
+ auto it = s_pending_stats->pages.find(&page);
+ if (it == s_pending_stats->pages.end())
+ return;
+ for (auto document : it->value.documents)
+ document->rendering_stats()->pending_page = nullptr;
+ s_pending_stats->dirty_pages.remove(&page);
+ s_pending_stats->pages.remove(it);
+}
+
+void Detail::begin_rendering_pending_operation(GC::Cell const* token, DOM::Document const& document, RenderingPendingReason reason)
+{
+ if (!Core::StatsLog::the() || document.is_decoded_svg())
+ return;
+ auto& operations = pending_stats().operations;
+ VERIFY(!operations.contains(token));
+ operations.set(token, PendingOperation { document, reason });
+ Detail::set_rendering_pending(document, reason, document.ensure_rendering_stats().pending[to_underlying(reason)] + 1);
+}
+
+void Detail::end_rendering_pending_operation(GC::Cell const* token)
+{
+ if (!s_pending_stats)
+ return;
+ auto operation = s_pending_stats->operations.take(token);
+ if (!operation.has_value())
+ return;
+ if (operation->stream) {
+ auto it = s_pending_stats->streams.find(operation->stream);
+ if (it != s_pending_stats->streams.end()) {
+ it->value.remove(token);
+ if (it->value.is_empty())
+ s_pending_stats->streams.remove(it);
+ }
+ }
+ if (!operation->document)
+ return;
+ auto& document = *operation->document;
+ auto& count = document.ensure_rendering_stats().pending[to_underlying(operation->reason)];
+ VERIFY(count);
+ Detail::set_rendering_pending(document, operation->reason, count - 1);
+}
+
+void Detail::track_rendering_pending_stream(GC::Cell const* token, Streams::ReadableStream& stream)
+{
+ if (!s_pending_stats)
+ return;
+ auto it = s_pending_stats->operations.find(token);
+ if (it == s_pending_stats->operations.end())
+ return;
+ // Closing a source with unread queued bytes need not close its identity transform. Observe the source's
+ // close request, before fetch installs that transform, so an unread response cannot keep the page pending.
+ if (!stream.is_readable() || (stream.controller().has_value() && stream.controller()->visit([](auto controller) { return controller->close_requested(); }))) {
+ end_rendering_pending_operation(token);
+ return;
+ }
+ VERIFY(!it->value.stream);
+ it->value.stream = &stream;
+ s_pending_stats->streams.ensure(&stream).set(token);
+}
+
+void Detail::complete_rendering_pending_stream(Streams::ReadableStream const& stream)
+{
+ if (!s_pending_stats)
+ return;
+ auto tokens = s_pending_stats->streams.take(&stream);
+ if (!tokens.has_value())
+ return;
+ for (auto token : *tokens)
+ end_rendering_pending_operation(token.ptr());
+}
+
+void Detail::did_update_rendering(DOM::Document& document)
+{
+ if (!Core::StatsLog::the())
+ return;
+ auto navigable = document.navigable();
+ if (!navigable || navigable->needs_repaint() || document.needs_animated_style_update())
+ return;
+ if (auto* style_computer = document.style_computer_if_created(); style_computer && style_computer->style_engine().has_recorded_input())
+ return;
+ // A no-op style/layout update can consume an invalidation without committing a presentation.
+ Detail::set_rendering_pending(document, RenderingPendingReason::NeedsRenderingUpdate, 0);
+}
+
+void Detail::flush_rendering_pending()
+{
+ auto* log = Core::StatsLog::the();
+ if (!log || !s_pending_stats || s_pending_stats->task_depth)
+ return;
+ auto dirty_pages = move(s_pending_stats->dirty_pages);
+ for (auto page : dirty_pages) {
+ auto it = s_pending_stats->pages.find(page);
+ if (it == s_pending_stats->pages.end() || !page->has_top_level_traversable())
+ continue;
+ auto& stats = it->value;
+ RenderingPendingCounts counts {};
+ for (auto document : stats.documents) {
+ auto const& document_stats = *document->rendering_stats();
+ auto navigable = document->navigable();
+ auto local_root = navigable->local_root();
+ if (local_root->parent() && !local_root->stats_ancestors_displayed())
+ continue;
+ if (!document_stats.displayed || document->visibility_state() != HTML::VisibilityState::Visible
+ || navigable->has_inclusive_ancestor_with_visibility_hidden())
+ continue;
+ if (auto intersection = navigable->viewport_intersection(); intersection.has_value() && intersection->is_empty())
+ continue;
+ for (size_t i = 0; i < counts.size(); ++i)
+ counts[i] += document_stats.pending[i];
+ }
+ if (stats.logged && counts == stats.last_counts)
+ continue;
+ static constexpr Array names {
+ "needs_rendering_update"sv,
+ "image_decodes"sv,
+ "font_loads"sv,
+ "style_sheet_loads"sv,
+ "resource_fetches_in_flight"sv,
+ "scheduled_animation_frame_callbacks"sv,
+ "load_event_delayers"sv,
+ "document_loads"sv,
+ };
+ static_assert(names.size() == to_underlying(RenderingPendingReason::Count));
+ JsonObject reasons;
+ bool pending = false;
+ for (size_t i = 0; i < names.size(); ++i) {
+ reasons.set(names[i], counts[i]);
+ pending |= counts[i] != 0;
+ }
+ JsonObject data;
+ data.set("page_id"sv, page->client().id().value());
+ data.set("navigable_id"sv, MUST(String::formatted("{}", page->top_level_traversable()->id())));
+ data.set("pending"sv, pending);
+ data.set("reasons"sv, move(reasons));
+ log->event("rendering_pending"sv, move(data));
+ stats.last_counts = counts;
+ stats.logged = true;
+ }
+}
+
+void Detail::begin_rendering_pending_task()
+{
+ flush_rendering_pending();
+ ++pending_stats().task_depth;
+}
+
+void Detail::end_rendering_pending_task()
+{
+ VERIFY(s_pending_stats && s_pending_stats->task_depth);
+ --s_pending_stats->task_depth;
+ flush_rendering_pending();
+}
+
+}
diff --git a/Libraries/LibWeb/Page/RenderingStats.h b/Libraries/LibWeb/Page/RenderingStats.h
new file mode 100644
index 00000000000..2950397fae1
--- /dev/null
+++ b/Libraries/LibWeb/Page/RenderingStats.h
@@ -0,0 +1,142 @@
+/*
+ * Copyright (c) 2026-present, the Ladybird developers.
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#pragma once
+
+#include <AK/Array.h>
+#include <LibCore/StatsLog.h>
+#include <LibGC/Ptr.h>
+#include <LibWeb/Export.h>
+#include <LibWeb/Forward.h>
+
+namespace Web {
+
+enum class RenderingPendingReason {
+ NeedsRenderingUpdate,
+ ImageDecodes,
+ FontLoads,
+ StyleSheetLoads,
+ ResourceFetchesInFlight,
+ ScheduledAnimationFrameCallbacks,
+ LoadEventDelayers,
+ DocumentLoads,
+ Count,
+};
+
+using RenderingPendingCounts = Array<u64, to_underlying(RenderingPendingReason::Count)>;
+
+struct RenderingStats {
+ AK_ALLOC_WITH_KMALLOC;
+
+ RenderingPendingCounts pending {};
+ GC::RawPtr<Page const> pending_page {};
+ bool displayed { true };
+};
+
+namespace Detail {
+
+WEB_API void set_rendering_pending(DOM::Document const& document, RenderingPendingReason reason, u64 count);
+WEB_API void rendering_pending_document_changed(DOM::Document const& document);
+WEB_API void set_rendering_pending_displayed(HTML::Navigable const& navigable, bool displayed);
+WEB_API void set_rendering_pending_ancestors_displayed(HTML::LocalNavigable&, bool);
+WEB_API void forget_rendering_stats(DOM::Document const& document);
+WEB_API void forget_rendering_pending(Page const& page);
+WEB_API void flush_rendering_pending();
+WEB_API void begin_rendering_pending_task();
+WEB_API void end_rendering_pending_task();
+WEB_API void did_update_rendering(DOM::Document& document);
+WEB_API void begin_rendering_pending_operation(GC::Cell const* token, DOM::Document const& document, RenderingPendingReason reason);
+WEB_API void end_rendering_pending_operation(GC::Cell const* token);
+WEB_API void track_rendering_pending_stream(GC::Cell const* token, Streams::ReadableStream& stream);
+WEB_API void complete_rendering_pending_stream(Streams::ReadableStream const& stream);
+
+}
+
+inline void set_rendering_pending(DOM::Document const& document, RenderingPendingReason reason, u64 count)
+{
+ if (Core::StatsLog::the())
+ Detail::set_rendering_pending(document, reason, count);
+}
+
+inline void rendering_pending_document_changed(DOM::Document const& document)
+{
+ if (Core::StatsLog::the())
+ Detail::rendering_pending_document_changed(document);
+}
+
+inline void set_rendering_pending_displayed(HTML::Navigable const& navigable, bool displayed)
+{
+ if (Core::StatsLog::the())
+ Detail::set_rendering_pending_displayed(navigable, displayed);
+}
+
+inline void set_rendering_pending_ancestors_displayed(HTML::LocalNavigable& navigable, bool displayed)
+{
+ if (Core::StatsLog::the())
+ Detail::set_rendering_pending_ancestors_displayed(navigable, displayed);
+}
+
+inline void forget_rendering_stats(DOM::Document const& document)
+{
+ if (Core::StatsLog::the())
+ Detail::forget_rendering_stats(document);
+}
+
+inline void forget_rendering_pending(Page const& page)
+{
+ if (Core::StatsLog::the())
+ Detail::forget_rendering_pending(page);
+}
+
+inline void flush_rendering_pending()
+{
+ if (Core::StatsLog::the())
+ Detail::flush_rendering_pending();
+}
+
+inline void begin_rendering_pending_task()
+{
+ if (Core::StatsLog::the())
+ Detail::begin_rendering_pending_task();
+}
+
+inline void end_rendering_pending_task()
+{
+ if (Core::StatsLog::the())
+ Detail::end_rendering_pending_task();
+}
+
+inline void did_update_rendering(DOM::Document& document)
+{
+ if (Core::StatsLog::the())
+ Detail::did_update_rendering(document);
+}
+
+inline void begin_rendering_pending_operation(GC::Cell const* token, DOM::Document const& document, RenderingPendingReason reason)
+{
+ if (Core::StatsLog::the())
+ Detail::begin_rendering_pending_operation(token, document, reason);
+}
+
+inline void end_rendering_pending_operation(GC::Cell const* token)
+{
+ if (Core::StatsLog::the())
+ Detail::end_rendering_pending_operation(token);
+}
+
+inline void track_rendering_pending_stream(GC::Cell const* token, Streams::ReadableStream& stream)
+{
+ if (Core::StatsLog::the())
+ Detail::track_rendering_pending_stream(token, stream);
+}
+
+inline void complete_rendering_pending_stream(Streams::ReadableStream const& stream)
+{
+ if (Core::StatsLog::the())
+ Detail::complete_rendering_pending_stream(stream);
+}
+
+}
diff --git a/Libraries/LibWeb/ResizeObserver/ResizeObserver.cpp b/Libraries/LibWeb/ResizeObserver/ResizeObserver.cpp
index 9d60e59d01d..da11f734f26 100644
--- a/Libraries/LibWeb/ResizeObserver/ResizeObserver.cpp
+++ b/Libraries/LibWeb/ResizeObserver/ResizeObserver.cpp
@@ -15,6 +15,7 @@
#include <LibWeb/HTML/Scripting/Environments.h>
#include <LibWeb/HTML/Window.h>
#include <LibWeb/Page/Page.h>
+#include <LibWeb/Page/RenderingStats.h>
#include <LibWeb/ResizeObserver/ResizeObserver.h>
#include <LibWeb/WebIDL/AbstractOperations.h>
#include <LibWeb/WebIDL/CallbackType.h>
@@ -120,6 +121,7 @@ void ResizeObserver::observe(DOM::Element& target, ResizeObserverOptions options
m_document->register_resize_observer({}, *this);
m_is_registered = true;
+ set_rendering_pending(*m_document, RenderingPendingReason::NeedsRenderingUpdate, 1);
m_document->page().client().request_frame();
update_activity_root();
}
diff --git a/Libraries/LibWeb/Streams/ReadableStream.cpp b/Libraries/LibWeb/Streams/ReadableStream.cpp
index 7a840d23ece..c9635c9c33e 100644
--- a/Libraries/LibWeb/Streams/ReadableStream.cpp
+++ b/Libraries/LibWeb/Streams/ReadableStream.cpp
@@ -20,6 +20,7 @@
#include <LibWeb/HTML/Scripting/TemporaryExecutionContext.h>
#include <LibWeb/HTML/StructuredSerialize.h>
#include <LibWeb/HTML/WindowOrWorkerGlobalScope.h>
+#include <LibWeb/Page/RenderingStats.h>
#include <LibWeb/Streams/AbstractOperations.h>
#include <LibWeb/Streams/BindingsGlue.h>
#include <LibWeb/Streams/ReadableByteStreamController.h>
@@ -136,6 +137,12 @@ namespace Web::Streams {
ReadableStream::~ReadableStream() = default;
+void ReadableStream::finalize()
+{
+ complete_rendering_pending_stream(*this);
+ Base::finalize();
+}
+
void ReadableStream::visit_edges(GC::Cell::Visitor& visitor)
{
Base::visit_edges(visitor);
diff --git a/Libraries/LibWeb/Streams/ReadableStream.h b/Libraries/LibWeb/Streams/ReadableStream.h
index 616a06be23f..f3df5b61a90 100644
--- a/Libraries/LibWeb/Streams/ReadableStream.h
+++ b/Libraries/LibWeb/Streams/ReadableStream.h
@@ -121,6 +121,7 @@ private:
ReadableStream();
virtual void visit_edges(GC::Cell::Visitor&) override;
+ virtual void finalize() override;
GC::Ptr<JS::Realm> m_realm;
GC::Ptr<JS::Realm> m_result_realm;
diff --git a/Libraries/LibWeb/Streams/ReadableStreamOperations.cpp b/Libraries/LibWeb/Streams/ReadableStreamOperations.cpp
index 62f188a953d..a8bd0fc19da 100644
--- a/Libraries/LibWeb/Streams/ReadableStreamOperations.cpp
+++ b/Libraries/LibWeb/Streams/ReadableStreamOperations.cpp
@@ -23,6 +23,7 @@
#include <LibWeb/Bindings/WrapperWorld.h>
#include <LibWeb/DOM/AbortSignal.h>
#include <LibWeb/HTML/Scripting/TemporaryExecutionContext.h>
+#include <LibWeb/Page/RenderingStats.h>
#include <LibWeb/Streams/AbstractOperations.h>
#include <LibWeb/Streams/BindingsGlue.h>
#include <LibWeb/Streams/ReadableByteStreamController.h>
@@ -873,6 +874,7 @@ void readable_stream_close(ReadableStream& stream)
// 2. Set stream.[[state]] to "closed".
stream.set_state(ReadableStream::State::Closed);
+ complete_rendering_pending_stream(stream);
// 3. Let reader be stream.[[reader]].
auto reader = stream.reader();
@@ -907,6 +909,7 @@ void readable_stream_error(ReadableStream& stream, JS::Value error)
// 2. Set stream.[[state]] to "errored".
stream.set_state(ReadableStream::State::Errored);
+ complete_rendering_pending_stream(stream);
// 3. Set stream.[[storedError]] to e.
stream.set_stored_error(error);
@@ -1397,6 +1400,7 @@ void readable_stream_default_controller_close(ReadableStreamDefaultController& c
// 3. Set controller.[[closeRequested]] to true.
controller.set_close_requested(true);
+ complete_rendering_pending_stream(*stream);
// 4. If controller.[[queue]] is empty,
if (controller.queue().is_empty()) {
@@ -1726,6 +1730,8 @@ WebIDL::ExceptionOr<void> readable_byte_stream_controller_close(JS::Realm& realm
if (controller.close_requested() || stream->state() != ReadableStream::State::Readable)
return {};
+ complete_rendering_pending_stream(*stream);
+
// 3. If controller.[[queueTotalSize]] > 0,
if (controller.queue_total_size() > 0.0) {
// 1. Set controller.[[closeRequested]] to true.
diff --git a/Libraries/LibWebView/CanonicalNavigable.cpp b/Libraries/LibWebView/CanonicalNavigable.cpp
index 2320365f787..c6e7c480cf5 100644
--- a/Libraries/LibWebView/CanonicalNavigable.cpp
+++ b/Libraries/LibWebView/CanonicalNavigable.cpp
@@ -954,6 +954,34 @@ void CanonicalNavigable::discard_pending_host(WebContentPage const& page)
abandon_populated_document(move(document_state));
}
+void CanonicalNavigable::set_stats_displayed(bool displayed)
+{
+ if (exchange(m_stats_displayed, displayed) != displayed)
+ send_stats_displayed_to_hosts();
+}
+
+void CanonicalNavigable::send_stats_displayed_to_hosts() const
+{
+ // An embedding change also changes the eligibility of hosted descendants.
+ RefPtr<WebContentPage> host = has_remote_host() ? &remote_host() : nullptr;
+ if (host)
+ send_stats_displayed_to(*host);
+ for_each_pending_host([&](WebContentPage& pending_host) {
+ if (&pending_host != host.ptr())
+ send_stats_displayed_to(pending_host);
+ });
+ for (auto const& child : children())
+ child->send_stats_displayed_to_hosts();
+}
+
+void CanonicalNavigable::send_stats_displayed_to(WebContentPage& host) const
+{
+ bool displayed = true;
+ for (auto const* ancestor = this; ancestor->parent(); ancestor = ancestor->parent())
+ displayed &= ancestor->m_stats_displayed;
+ host.async_set_rendering_stats_displayed(id(), displayed);
+}
+
void CanonicalNavigable::set_viewport(Web::DevicePixelRect viewport_rect, Web::DevicePixelRect viewport_intersection, double device_pixel_ratio)
{
m_viewport_rect = viewport_rect;
@@ -978,6 +1006,8 @@ void CanonicalNavigable::send_viewport_to_host() const
void CanonicalNavigable::send_viewport_to(WebContentPage& host) const
{
host.async_set_hosted_root_viewport(id(), m_viewport_rect->size(), m_viewport_intersection, m_device_pixel_ratio);
+ if (Core::StatsLog::the())
+ send_stats_displayed_to(host);
}
void CanonicalNavigable::set_hosted_state(Web::HTML::HostedNavigableState state)
diff --git a/Libraries/LibWebView/CanonicalNavigable.h b/Libraries/LibWebView/CanonicalNavigable.h
index 23359979d83..ffcf9ad9b7a 100644
--- a/Libraries/LibWebView/CanonicalNavigable.h
+++ b/Libraries/LibWebView/CanonicalNavigable.h
@@ -175,6 +175,9 @@ public:
void set_viewport(Web::DevicePixelRect, Web::DevicePixelRect viewport_intersection, double device_pixel_ratio);
void send_viewport_to_host() const;
void send_viewport_to(WebContentPage&) const;
+ void set_stats_displayed(bool);
+ void send_stats_displayed_to_hosts() const;
+ void send_stats_displayed_to(WebContentPage&) const;
// The navigable's replicated state: what its host reports, and what the UI process knows of it.
Optional<Web::HTML::ReplicatedNavigableState> replicated_state() const;
@@ -265,6 +268,7 @@ private:
BlobURLHandle m_pending_navigation_blob_url;
BlobURLHandle m_document_blob_url;
ActiveDocumentLoad m_active_document_load;
+ bool m_stats_displayed { false };
Optional<Web::DevicePixelRect> m_viewport_rect;
Web::DevicePixelRect m_viewport_intersection;
double m_device_pixel_ratio { 1 };
diff --git a/Libraries/LibWebView/WebContentPage.cpp b/Libraries/LibWebView/WebContentPage.cpp
index d5cc90f9d5f..9ca99c3bc42 100644
--- a/Libraries/LibWebView/WebContentPage.cpp
+++ b/Libraries/LibWebView/WebContentPage.cpp
@@ -9,6 +9,7 @@
#include <AK/JsonObject.h>
#include <LibCore/ElapsedTimer.h>
#include <LibCore/EventLoop.h>
+#include <LibCore/StatsLog.h>
#include <LibDevTools/StorageHelpers.h>
#include <LibHTTP/Cookie/ParsedCookie.h>
#include <LibWebCommon/HTML/BrowsingContext.h>
@@ -2143,6 +2144,16 @@ void WebContentPage::did_change_navigable_container_state(Web::HTML::CrossProces
navigable->update_container_state(move(state));
}
+void WebContentPage::did_update_frame_stats_displayed(Web::HTML::CrossProcessId frame_id, bool displayed)
+{
+ if (!Core::StatsLog::the())
+ return;
+ auto child_frame = traversable().find(frame_id);
+ if (!child_frame.has_value() || !holds_container_of(*child_frame, "did_update_frame_stats_displayed"sv))
+ return;
+ child_frame->set_stats_displayed(displayed);
+}
+
void WebContentPage::did_update_child_frame_viewport(Web::HTML::CrossProcessId frame_id, Web::DevicePixelRect viewport_rect, Web::DevicePixelRect viewport_intersection, double device_pixel_ratio)
{
auto child_frame = traversable().find(frame_id);
diff --git a/Libraries/LibWebView/WebContentPage.h b/Libraries/LibWebView/WebContentPage.h
index 3cb8f09d5bf..c5dbe1d0a79 100644
--- a/Libraries/LibWebView/WebContentPage.h
+++ b/Libraries/LibWebView/WebContentPage.h
@@ -306,6 +306,7 @@ private:
virtual void did_set_opener_browsing_context(Web::HTML::CrossProcessId navigable_id, Optional<Web::HTML::CrossProcessId> opener_navigable_id) override;
virtual void did_change_navigable_container_state(Web::HTML::CrossProcessId navigable_id, Web::HTML::ReplicatedContainerState state) override;
virtual void did_update_child_frame_viewport(Web::HTML::CrossProcessId frame_id, Web::DevicePixelRect viewport_rect, Web::DevicePixelRect viewport_intersection, double device_pixel_ratio) override;
+ virtual void did_update_frame_stats_displayed(Web::HTML::CrossProcessId, bool) override;
virtual void did_forward_mouse_event_to_child_frame(Web::HTML::CrossProcessId frame_id, Web::MouseEvent) override;
virtual void did_destroy_child_frame(Web::HTML::CrossProcessId frame_id) override;
Messages::WebContentClient::DidStartDownloadWithoutRequestResponse did_start_download_without_request(URL::URL url, ByteString suggested_filename, Optional<u64> total_size);
diff --git a/Services/WebContent/ConnectionFromClient.cpp b/Services/WebContent/ConnectionFromClient.cpp
index eb07f3582fb..fa2eb50b0b1 100644
--- a/Services/WebContent/ConnectionFromClient.cpp
+++ b/Services/WebContent/ConnectionFromClient.cpp
@@ -86,6 +86,7 @@
#include <LibWeb/Loader/ResourceLoader.h>
#include <LibWeb/Loader/SourceHighlighter.h>
#include <LibWeb/Namespace.h>
+#include <LibWeb/Page/RenderingStats.h>
#include <LibWeb/Painting/BoxViews.h>
#include <LibWeb/Painting/DocumentPaintState.h>
#include <LibWeb/Painting/FlexboxInspectorOverlay.h>
@@ -223,6 +224,17 @@ void ConnectionFromClient::stop_hosting_navigable(Web::PageId page_id, Web::HTML
}
}
+void ConnectionFromClient::set_rendering_stats_displayed(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, bool displayed)
+{
+ if (!Core::StatsLog::the())
+ return;
+ if (auto page = this->page(page_id); page.has_value()) {
+ auto* navigable = as_if<Web::HTML::LocalNavigable>(page->page().navigable_with_id(navigable_id).ptr());
+ if (navigable && navigable->is_local_root())
+ Web::set_rendering_pending_ancestors_displayed(*navigable, displayed);
+ }
+}
+
void ConnectionFromClient::set_hosted_root_viewport(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Web::DevicePixelSize size, Web::DevicePixelRect viewport_intersection, double device_pixel_ratio)
{
if (auto page = this->page(page_id); page.has_value())
diff --git a/Services/WebContent/ConnectionFromClient.h b/Services/WebContent/ConnectionFromClient.h
index bb2c0d5e3f8..a2e91ca98d2 100644
--- a/Services/WebContent/ConnectionFromClient.h
+++ b/Services/WebContent/ConnectionFromClient.h
@@ -139,6 +139,7 @@ private:
virtual void discard_provisional_navigable(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id) override;
virtual void stop_hosting_navigable(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::ReplicatedNavigableState) override;
virtual void set_hosted_root_viewport(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Web::DevicePixelSize, Web::DevicePixelRect viewport_intersection, double device_pixel_ratio) override;
+ virtual void set_rendering_stats_displayed(Web::PageId, Web::HTML::CrossProcessId, bool) override;
virtual void run_beforeunload_check(Web::PageId page_id, Web::HTML::CrossProcessId check_id, Vector<Web::HTML::CrossProcessId> navigable_ids, Optional<Web::HTML::SessionHistoryEntryDescriptor> target_entry, Optional<Web::HTML::UserNavigationInvolvement> user_involvement_for_navigate_event, Web::HTML::UnloadPromptShown unload_prompt_shown) override;
virtual void discard_embedded_page(Web::PageId page_id) override;
virtual void queue_navigation_api_state_clear_task(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id) override;
diff --git a/Services/WebContent/PageClient.cpp b/Services/WebContent/PageClient.cpp
index d9bfdfd5ec1..22b124c6b97 100644
--- a/Services/WebContent/PageClient.cpp
+++ b/Services/WebContent/PageClient.cpp
@@ -406,6 +406,11 @@ void PageClient::page_did_create_child_frame(Web::HTML::CrossProcessId parent_fr
client().async_did_create_child_frame(m_id, parent_frame_id, container_document.id(), frame_id, replicated_state, initial_history_entry, origin, environment_id, document_id);
}
+void PageClient::page_did_update_frame_stats_displayed(Web::HTML::CrossProcessId frame_id, bool displayed)
+{
+ client().async_did_update_frame_stats_displayed(m_id, frame_id, displayed);
+}
+
void PageClient::page_did_update_child_frame_viewport(Web::HTML::CrossProcessId frame_id, Web::DevicePixelRect viewport_rect, Web::DevicePixelRect viewport_intersection)
{
client().async_did_update_child_frame_viewport(m_id, frame_id, viewport_rect, viewport_intersection, page().client().device_pixel_ratio());
diff --git a/Services/WebContent/PageClient.h b/Services/WebContent/PageClient.h
index 4d01ef833fe..3952019d2f4 100644
--- a/Services/WebContent/PageClient.h
+++ b/Services/WebContent/PageClient.h
@@ -202,6 +202,7 @@ private:
virtual void page_did_create_populated_document_with_an_origin_of_its_own(Web::HTML::CrossProcessId navigable_id, Web::HTML::CrossProcessId document_id, Web::HTML::PopulatedDocumentOrigin, Web::HTML::EnvironmentId const& environment_id) override;
virtual void page_did_create_child_frame(Web::HTML::CrossProcessId parent_frame_id, Web::DOM::Document const& container_document, Web::HTML::CrossProcessId frame_id, Web::HTML::HostedNavigableState const&, Web::HTML::PendingSessionHistoryEntryDescriptor const& initial_history_entry, URL::Origin const& origin, Web::HTML::EnvironmentId const& environment_id, Web::HTML::CrossProcessId document_id) override;
virtual void page_did_update_child_frame_viewport(Web::HTML::CrossProcessId frame_id, Web::DevicePixelRect viewport_rect, Web::DevicePixelRect viewport_intersection) override;
+ virtual void page_did_update_frame_stats_displayed(Web::HTML::CrossProcessId, bool) override;
virtual void forward_mouse_event_to_remote_navigable(Web::PageId, Web::HTML::CrossProcessId navigable_id, Web::MouseEvent) override;
virtual void page_did_destroy_child_frame(Web::HTML::CrossProcessId frame_id) override;
virtual String dump_site_isolation_process_tree_for_testing() override;
diff --git a/Services/WebContent/WebContentClient.ipc b/Services/WebContent/WebContentClient.ipc
index fa3fc102fe9..0bf22a42b89 100644
--- a/Services/WebContent/WebContentClient.ipc
+++ b/Services/WebContent/WebContentClient.ipc
@@ -102,6 +102,7 @@ endpoint WebContentClient routed by Web::PageId page_id
did_set_opener_browsing_context(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Optional<Web::HTML::CrossProcessId> opener_navigable_id) =|
did_completely_finish_loading(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::CrossProcessId document_id) =|
did_change_navigable_container_state(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::ReplicatedContainerState state) =|
+ did_update_frame_stats_displayed(Web::PageId page_id, Web::HTML::CrossProcessId frame_id, bool displayed) =|
did_update_child_frame_viewport(Web::PageId page_id, Web::HTML::CrossProcessId frame_id, Web::DevicePixelRect viewport_rect, Web::DevicePixelRect viewport_intersection, double device_pixel_ratio) =|
did_forward_mouse_event_to_child_frame(Web::PageId page_id, Web::HTML::CrossProcessId frame_id, Web::MouseEvent event) =|
did_destroy_child_frame(Web::PageId page_id, Web::HTML::CrossProcessId frame_id) =|
diff --git a/Services/WebContent/WebContentServer.ipc b/Services/WebContent/WebContentServer.ipc
index cf34338a201..1d5353ba892 100644
--- a/Services/WebContent/WebContentServer.ipc
+++ b/Services/WebContent/WebContentServer.ipc
@@ -113,6 +113,7 @@ endpoint WebContentServer routed by Web::PageId page_id
set_browsing_context_group(Web::PageId page_id, u64 browsing_context_group_id) =|
discard_provisional_navigable(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id) =|
stop_hosting_navigable(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Web::HTML::ReplicatedNavigableState replicated_state) =|
+ set_rendering_stats_displayed(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, bool displayed) =|
set_hosted_root_viewport(Web::PageId page_id, Web::HTML::CrossProcessId navigable_id, Web::DevicePixelSize size, Web::DevicePixelRect viewport_intersection, double device_pixel_ratio) =|
run_beforeunload_check(Web::PageId page_id, Web::HTML::CrossProcessId check_id, Vector<Web::HTML::CrossProcessId> navigable_ids, Optional<Web::HTML::SessionHistoryEntryDescriptor> target_entry, Optional<Web::HTML::UserNavigationInvolvement> user_involvement_for_navigate_event, Web::HTML::UnloadPromptShown unload_prompt_shown) =|
discard_embedded_page(Web::PageId page_id) =|