mirror of
https://github.com/fergalmoran/ladybird.git
synced 2026-01-04 15:45:25 +00:00
LibWeb+WebContent: Add a simple API for running arbitrary JavaScript
This patch adds OutOfProcessWebView::run_javascript(StringView). This can be used by the OOPWV embedder to execute arbitrary JavaScript in the top-level browsing context on the WebContent process side.
This commit is contained in:
@@ -242,6 +242,23 @@ void ClientConnection::js_console_input(const String& js_source)
|
||||
m_console_client->handle_input(js_source);
|
||||
}
|
||||
|
||||
void ClientConnection::run_javascript(String const& js_source)
|
||||
{
|
||||
if (!page().top_level_browsing_context().document())
|
||||
return;
|
||||
|
||||
auto& interpreter = page().top_level_browsing_context().document()->interpreter();
|
||||
|
||||
auto parser = JS::Parser(JS::Lexer(js_source));
|
||||
auto program = parser.parse_program();
|
||||
interpreter.run(interpreter.global_object(), *program);
|
||||
|
||||
if (interpreter.vm().exception()) {
|
||||
dbgln("Exception :(");
|
||||
interpreter.vm().clear_exception();
|
||||
}
|
||||
}
|
||||
|
||||
Messages::WebContentServer::GetSelectedTextResponse ClientConnection::get_selected_text()
|
||||
{
|
||||
return page().focused_context().selected_text();
|
||||
|
||||
Reference in New Issue
Block a user