Skip to content

Commit ddbdeb3

Browse files
committed
Ladybird: Add --dump-layout-tree mode that dumps layout tree and exits
1 parent 90fee39 commit ddbdeb3

File tree

3 files changed

+27
-6
lines changed

3 files changed

+27
-6
lines changed

Ladybird/WebContentView.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1055,3 +1055,8 @@ void WebContentView::notify_server_did_get_accessibility_tree(DeprecatedString c
10551055
{
10561056
dbgln("TODO: support accessibility tree in Ladybird");
10571057
}
1058+
1059+
ErrorOr<String> WebContentView::dump_layout_tree()
1060+
{
1061+
return String::from_deprecated_string(client().dump_layout_tree());
1062+
}

Ladybird/WebContentView.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,8 @@ class WebContentView final
9494
void show_js_console();
9595
void show_inspector();
9696

97+
ErrorOr<String> dump_layout_tree();
98+
9799
Gfx::IntPoint to_content(Gfx::IntPoint) const;
98100
Gfx::IntPoint to_widget(Gfx::IntPoint) const;
99101

Ladybird/main.cpp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "BrowserWindow.h"
88
#include "Settings.h"
99
#include "Utilities.h"
10+
#include "WebContentView.h"
1011
#include <Browser/CookieJar.h>
1112
#include <Browser/Database.h>
1213
#include <LibCore/ArgsParser.h>
@@ -68,13 +69,32 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
6869

6970
StringView raw_url;
7071
StringView webdriver_content_ipc_path;
72+
bool dump_layout_tree;
7173

7274
Core::ArgsParser args_parser;
7375
args_parser.set_general_help("The Ladybird web browser :^)");
7476
args_parser.add_positional_argument(raw_url, "URL to open", "url", Core::ArgsParser::Required::No);
7577
args_parser.add_option(webdriver_content_ipc_path, "Path to WebDriver IPC for WebContent", "webdriver-content-path", 0, "path");
78+
args_parser.add_option(dump_layout_tree, "Dump layout tree and exit", "dump-layout-tree", 'd');
7679
args_parser.parse(arguments);
7780

81+
URL url = raw_url;
82+
if (Core::File::exists(raw_url))
83+
url = URL::create_with_file_scheme(Core::File::real_path_for(raw_url));
84+
else if (!url.is_valid())
85+
url = DeprecatedString::formatted("http://{}", raw_url);
86+
87+
if (dump_layout_tree) {
88+
WebContentView view({});
89+
view.on_load_finish = [&](auto&) {
90+
auto dump = view.dump_layout_tree().release_value_but_fixme_should_propagate_errors();
91+
outln("{}", dump);
92+
_exit(0);
93+
};
94+
view.load(url);
95+
return app.exec();
96+
}
97+
7898
auto cookie_jar = TRY(Browser::CookieJar::create(*database));
7999

80100
BrowserWindow window(cookie_jar, webdriver_content_ipc_path);
@@ -83,12 +103,6 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
83103
window.resize(800, 600);
84104
window.show();
85105

86-
URL url = raw_url;
87-
if (Core::File::exists(raw_url))
88-
url = URL::create_with_file_scheme(Core::File::real_path_for(raw_url));
89-
else if (!url.is_valid())
90-
url = DeprecatedString::formatted("http://{}", raw_url);
91-
92106
if (url.is_valid())
93107
window.view().load(url);
94108

0 commit comments

Comments
 (0)