mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-08-18 08:20:44 +00:00
LibWebView+WebContent: Begin supporting the DevTools JavaScript console
This supports evaluating the script and replying with the result. We currently serialize JS objects to a string, but we will need to support dynamic interaction with the objects over IPC. This does not yet support sending console messages to DevTools.
This commit is contained in:
parent
6d33b70e61
commit
32bc2dc7b6
Notes:
github-actions[bot]
2025-02-28 12:09:35 +00:00
Author: https://github.com/trflynn89
Commit: 32bc2dc7b6
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/3686
10 changed files with 101 additions and 2 deletions
|
@ -417,4 +417,20 @@ void Application::clear_highlighted_dom_node(DevTools::TabDescription const& des
|
|||
view->clear_highlighted_dom_node();
|
||||
}
|
||||
|
||||
void Application::evaluate_javascript(DevTools::TabDescription const& description, String script, OnScriptEvaluationComplete on_complete) const
|
||||
{
|
||||
auto view = ViewImplementation::find_view_by_id(description.id);
|
||||
if (!view.has_value()) {
|
||||
on_complete(Error::from_string_literal("Unable to locate tab"));
|
||||
return;
|
||||
}
|
||||
|
||||
view->on_received_js_console_result = [&view = *view, on_complete = move(on_complete)](JsonValue result) {
|
||||
view.on_received_js_console_result = nullptr;
|
||||
on_complete(move(result));
|
||||
};
|
||||
|
||||
view->js_console_input(move(script));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -96,6 +96,7 @@ private:
|
|||
virtual void clear_inspected_dom_node(DevTools::TabDescription const&) const override;
|
||||
virtual void highlight_dom_node(DevTools::TabDescription const&, Web::UniqueNodeID, Optional<Web::CSS::Selector::PseudoElement::Type>) const override;
|
||||
virtual void clear_highlighted_dom_node(DevTools::TabDescription const&) const override;
|
||||
virtual void evaluate_javascript(DevTools::TabDescription const&, String, OnScriptEvaluationComplete) const override;
|
||||
|
||||
static Application* s_the;
|
||||
|
||||
|
|
|
@ -215,6 +215,7 @@ public:
|
|||
Function<void(Web::UniqueNodeID)> on_received_hovered_node_id;
|
||||
Function<void(Optional<Web::UniqueNodeID> const& node_id)> on_finshed_editing_dom_node;
|
||||
Function<void(String const&)> on_received_dom_node_html;
|
||||
Function<void(JsonValue)> on_received_js_console_result;
|
||||
Function<void(i32 message_id)> on_received_console_message;
|
||||
Function<void(i32 start_index, Vector<String> const& message_types, Vector<String> const& messages)> on_received_console_messages;
|
||||
Function<void(i32 count_waiting)> on_resource_status_change;
|
||||
|
|
|
@ -366,6 +366,14 @@ void WebContentClient::did_get_internal_page_info(u64 page_id, WebView::PageInfo
|
|||
view->did_receive_internal_page_info({}, type, info);
|
||||
}
|
||||
|
||||
void WebContentClient::did_execute_js_console_input(u64 page_id, JsonValue const& result)
|
||||
{
|
||||
if (auto view = view_for_page_id(page_id); view.has_value()) {
|
||||
if (view->on_received_js_console_result)
|
||||
view->on_received_js_console_result(move(const_cast<JsonValue&>(result)));
|
||||
}
|
||||
}
|
||||
|
||||
void WebContentClient::did_output_js_console_message(u64 page_id, i32 message_index)
|
||||
{
|
||||
if (auto view = view_for_page_id(page_id); view.has_value()) {
|
||||
|
|
|
@ -79,6 +79,7 @@ private:
|
|||
virtual void did_get_dom_node_html(u64 page_id, String const& html) override;
|
||||
virtual void did_take_screenshot(u64 page_id, Gfx::ShareableBitmap const& screenshot) override;
|
||||
virtual void did_get_internal_page_info(u64 page_id, PageInfoType, String const&) override;
|
||||
virtual void did_execute_js_console_input(u64 page_id, JsonValue const&) override;
|
||||
virtual void did_output_js_console_message(u64 page_id, i32 message_index) override;
|
||||
virtual void did_get_js_console_messages(u64 page_id, i32 start_index, Vector<String> const& message_types, Vector<String> const& messages) override;
|
||||
virtual void did_change_favicon(u64 page_id, Gfx::ShareableBitmap const&) override;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue