mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 15:12:45 +00:00 
			
		
		
		
	Ladybird: Add --dump-layout-tree mode that dumps layout tree and exits
This commit is contained in:
		
							parent
							
								
									90fee39290
								
							
						
					
					
						commit
						ddbdeb3ca0
					
				
					 3 changed files with 27 additions and 6 deletions
				
			
		|  | @ -7,6 +7,7 @@ | |||
| #include "BrowserWindow.h" | ||||
| #include "Settings.h" | ||||
| #include "Utilities.h" | ||||
| #include "WebContentView.h" | ||||
| #include <Browser/CookieJar.h> | ||||
| #include <Browser/Database.h> | ||||
| #include <LibCore/ArgsParser.h> | ||||
|  | @ -68,13 +69,32 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | |||
| 
 | ||||
|     StringView raw_url; | ||||
|     StringView webdriver_content_ipc_path; | ||||
|     bool dump_layout_tree; | ||||
| 
 | ||||
|     Core::ArgsParser args_parser; | ||||
|     args_parser.set_general_help("The Ladybird web browser :^)"); | ||||
|     args_parser.add_positional_argument(raw_url, "URL to open", "url", Core::ArgsParser::Required::No); | ||||
|     args_parser.add_option(webdriver_content_ipc_path, "Path to WebDriver IPC for WebContent", "webdriver-content-path", 0, "path"); | ||||
|     args_parser.add_option(dump_layout_tree, "Dump layout tree and exit", "dump-layout-tree", 'd'); | ||||
|     args_parser.parse(arguments); | ||||
| 
 | ||||
|     URL url = raw_url; | ||||
|     if (Core::File::exists(raw_url)) | ||||
|         url = URL::create_with_file_scheme(Core::File::real_path_for(raw_url)); | ||||
|     else if (!url.is_valid()) | ||||
|         url = DeprecatedString::formatted("http://{}", raw_url); | ||||
| 
 | ||||
|     if (dump_layout_tree) { | ||||
|         WebContentView view({}); | ||||
|         view.on_load_finish = [&](auto&) { | ||||
|             auto dump = view.dump_layout_tree().release_value_but_fixme_should_propagate_errors(); | ||||
|             outln("{}", dump); | ||||
|             _exit(0); | ||||
|         }; | ||||
|         view.load(url); | ||||
|         return app.exec(); | ||||
|     } | ||||
| 
 | ||||
|     auto cookie_jar = TRY(Browser::CookieJar::create(*database)); | ||||
| 
 | ||||
|     BrowserWindow window(cookie_jar, webdriver_content_ipc_path); | ||||
|  | @ -83,12 +103,6 @@ ErrorOr<int> serenity_main(Main::Arguments arguments) | |||
|     window.resize(800, 600); | ||||
|     window.show(); | ||||
| 
 | ||||
|     URL url = raw_url; | ||||
|     if (Core::File::exists(raw_url)) | ||||
|         url = URL::create_with_file_scheme(Core::File::real_path_for(raw_url)); | ||||
|     else if (!url.is_valid()) | ||||
|         url = DeprecatedString::formatted("http://{}", raw_url); | ||||
| 
 | ||||
|     if (url.is_valid()) | ||||
|         window.view().load(url); | ||||
| 
 | ||||
|  |  | |||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Andreas Kling
						Andreas Kling