File tree Expand file tree Collapse file tree 5 files changed +27
-0
lines changed Expand file tree Collapse file tree 5 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -412,6 +412,11 @@ void OutOfProcessWebView::js_console_input(const String& js_source)
412
412
client ().async_js_console_input (js_source);
413
413
}
414
414
415
+ void OutOfProcessWebView::run_javascript (StringView js_source)
416
+ {
417
+ client ().async_run_javascript (js_source);
418
+ }
419
+
415
420
String OutOfProcessWebView::selected_text ()
416
421
{
417
422
return client ().get_selected_text ();
Original file line number Diff line number Diff line change @@ -35,6 +35,8 @@ class OutOfProcessWebView final
35
35
void js_console_initialize ();
36
36
void js_console_input (const String& js_source);
37
37
38
+ void run_javascript (StringView);
39
+
38
40
String selected_text ();
39
41
void select_all ();
40
42
Original file line number Diff line number Diff line change @@ -242,6 +242,23 @@ void ClientConnection::js_console_input(const String& js_source)
242
242
m_console_client->handle_input (js_source);
243
243
}
244
244
245
+ void ClientConnection::run_javascript (String const & js_source)
246
+ {
247
+ if (!page ().top_level_browsing_context ().document ())
248
+ return ;
249
+
250
+ auto & interpreter = page ().top_level_browsing_context ().document ()->interpreter ();
251
+
252
+ auto parser = JS::Parser (JS::Lexer (js_source));
253
+ auto program = parser.parse_program ();
254
+ interpreter.run (interpreter.global_object (), *program);
255
+
256
+ if (interpreter.vm ().exception ()) {
257
+ dbgln (" Exception :(" );
258
+ interpreter.vm ().clear_exception ();
259
+ }
260
+ }
261
+
245
262
Messages::WebContentServer::GetSelectedTextResponse ClientConnection::get_selected_text ()
246
263
{
247
264
return page ().focused_context ().selected_text ();
Original file line number Diff line number Diff line change @@ -51,6 +51,7 @@ class ClientConnection final
51
51
virtual void inspect_dom_tree () override ;
52
52
virtual void js_console_initialize () override ;
53
53
virtual void js_console_input (String const &) override ;
54
+ virtual void run_javascript (String const &) override ;
54
55
virtual Messages::WebContentServer::GetSelectedTextResponse get_selected_text () override ;
55
56
virtual void select_all () override ;
56
57
Original file line number Diff line number Diff line change @@ -30,6 +30,8 @@ endpoint WebContentServer
30
30
js_console_initialize() =|
31
31
js_console_input(String js_source) =|
32
32
33
+ run_javascript(String js_source) =|
34
+
33
35
get_selected_text() => (String selection)
34
36
select_all() =|
35
37
}
You can’t perform that action at this time.
0 commit comments