1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 20:17:44 +00:00

WebContent+headless-browser: Use document.body.innerText for text tests

This should be less fickle than the "select all & copy selected text"
trick we were doing earlier.
This commit is contained in:
Andreas Kling 2023-05-28 20:54:33 +02:00
parent 58c1cb80bb
commit 097b5e4803
4 changed files with 19 additions and 4 deletions

View file

@ -636,6 +636,16 @@ Messages::WebContentServer::DumpLayoutTreeResponse ConnectionFromClient::dump_la
return builder.to_deprecated_string();
}
Messages::WebContentServer::DumpTextResponse ConnectionFromClient::dump_text()
{
auto* document = page().top_level_browsing_context().active_document();
if (!document)
return DeprecatedString { "(no DOM tree)" };
if (!document->body())
return DeprecatedString { "(no body)" };
return document->body()->inner_text();
}
void ConnectionFromClient::set_content_filters(Vector<String> const& filters)
{
Web::ContentFilter::the().set_patterns(filters).release_value_but_fixme_should_propagate_errors();

View file

@ -74,6 +74,7 @@ private:
virtual void inspect_accessibility_tree() override;
virtual Messages::WebContentServer::GetHoveredNodeIdResponse get_hovered_node_id() override;
virtual Messages::WebContentServer::DumpLayoutTreeResponse dump_layout_tree() override;
virtual Messages::WebContentServer::DumpTextResponse dump_text() override;
virtual void set_content_filters(Vector<String> const&) override;
virtual void set_autoplay_allowed_on_all_websites() override;
virtual void set_autoplay_allowlist(Vector<String> const& allowlist) override;

View file

@ -50,6 +50,7 @@ endpoint WebContentServer
run_javascript(DeprecatedString js_source) =|
dump_layout_tree() => (DeprecatedString dump)
dump_text() => (DeprecatedString dump)
get_selected_text() => (DeprecatedString selection)
select_all() =|