mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 06:14:58 +00:00
LibWeb+WebContent: Add option to dump session history of a traversable
This commit is contained in:
parent
537bf4c917
commit
aef4b84e22
4 changed files with 37 additions and 0 deletions
|
@ -195,6 +195,12 @@ BrowserWindow::BrowserWindow(Vector<URL> const& initial_urls, WebView::CookieJar
|
|||
|
||||
auto* debug_menu = menuBar()->addMenu("&Debug");
|
||||
|
||||
auto* dump_session_history_tree_action = new QAction("Dump Session History Tree", this);
|
||||
debug_menu->addAction(dump_session_history_tree_action);
|
||||
QObject::connect(dump_session_history_tree_action, &QAction::triggered, this, [this] {
|
||||
debug_request("dump-session-history");
|
||||
});
|
||||
|
||||
auto* dump_dom_tree_action = new QAction("Dump &DOM Tree", this);
|
||||
dump_dom_tree_action->setIcon(QIcon(QString("%1/res/icons/browser/dom-tree.png").arg(s_serenity_resource_root.characters())));
|
||||
debug_menu->addAction(dump_dom_tree_action);
|
||||
|
|
|
@ -23,9 +23,11 @@
|
|||
#include <LibWeb/DOM/ShadowRoot.h>
|
||||
#include <LibWeb/DOM/Text.h>
|
||||
#include <LibWeb/Dump.h>
|
||||
#include <LibWeb/HTML/DocumentState.h>
|
||||
#include <LibWeb/HTML/HTMLImageElement.h>
|
||||
#include <LibWeb/HTML/HTMLTemplateElement.h>
|
||||
#include <LibWeb/HTML/ImageRequest.h>
|
||||
#include <LibWeb/HTML/TraversableNavigable.h>
|
||||
#include <LibWeb/Layout/BlockContainer.h>
|
||||
#include <LibWeb/Layout/FormattingContext.h>
|
||||
#include <LibWeb/Layout/FrameBox.h>
|
||||
|
@ -46,6 +48,28 @@ static void indent(StringBuilder& builder, int levels)
|
|||
builder.append(" "sv);
|
||||
}
|
||||
|
||||
static ErrorOr<void> dump_session_history_entry(StringBuilder& builder, HTML::SessionHistoryEntry const& session_history_entry, int indent_levels)
|
||||
{
|
||||
indent(builder, indent_levels);
|
||||
auto const& document = session_history_entry.document_state->document();
|
||||
TRY(builder.try_appendff("step=({}) url=({}) is-active=({})\n", session_history_entry.step.get<int>(), session_history_entry.url, document && document->is_active()));
|
||||
for (auto const& nested_history : session_history_entry.document_state->nested_histories()) {
|
||||
for (auto const& nested_she : nested_history.entries) {
|
||||
TRY(dump_session_history_entry(builder, *nested_she, indent_levels + 1));
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
void dump_tree(HTML::TraversableNavigable& traversable)
|
||||
{
|
||||
StringBuilder builder;
|
||||
for (auto const& she : traversable.session_history_entries()) {
|
||||
dump_session_history_entry(builder, *she, 0).release_value_but_fixme_should_propagate_errors();
|
||||
}
|
||||
dbgln("{}", builder.string_view());
|
||||
}
|
||||
|
||||
void dump_tree(DOM::Node const& node)
|
||||
{
|
||||
StringBuilder builder;
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
|
||||
namespace Web {
|
||||
|
||||
void dump_tree(HTML::TraversableNavigable&);
|
||||
void dump_tree(StringBuilder&, DOM::Node const&);
|
||||
void dump_tree(DOM::Node const&);
|
||||
void dump_tree(StringBuilder&, Layout::Node const&, bool show_box_model = false, bool show_specified_style = false, bool colorize = false);
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <LibWeb/HTML/BrowsingContext.h>
|
||||
#include <LibWeb/HTML/Scripting/ClassicScript.h>
|
||||
#include <LibWeb/HTML/Storage.h>
|
||||
#include <LibWeb/HTML/TraversableNavigable.h>
|
||||
#include <LibWeb/HTML/Window.h>
|
||||
#include <LibWeb/Layout/Viewport.h>
|
||||
#include <LibWeb/Loader/ContentFilter.h>
|
||||
|
@ -359,6 +360,11 @@ void ConnectionFromClient::report_finished_handling_input_event(bool event_was_h
|
|||
|
||||
void ConnectionFromClient::debug_request(DeprecatedString const& request, DeprecatedString const& argument)
|
||||
{
|
||||
if (request == "dump-session-history") {
|
||||
auto const& traversable = page().top_level_traversable();
|
||||
Web::dump_tree(*traversable);
|
||||
}
|
||||
|
||||
if (request == "dump-dom-tree") {
|
||||
if (auto* doc = page().top_level_browsing_context().active_document())
|
||||
Web::dump_tree(*doc);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue