diff --git a/support/hololens/ServoApp/BrowserPage.cpp b/support/hololens/ServoApp/BrowserPage.cpp
index 136490bab63..e4f460d3497 100644
--- a/support/hololens/ServoApp/BrowserPage.cpp
+++ b/support/hololens/ServoApp/BrowserPage.cpp
@@ -335,6 +335,15 @@ void BrowserPage::OnDevtoolsButtonClicked(IInspectable const &,
}
}
+void BrowserPage::OnJSInputEdited(IInspectable const &,
+ Input::KeyRoutedEventArgs const &e) {
+ if (e.Key() == Windows::System::VirtualKey::Enter) {
+ auto input = JSInput().Text();
+ JSInput().Text(L"");
+ mDevtoolsClient->Evaluate(input);
+ }
+}
+
void BrowserPage::OnURLEdited(IInspectable const &,
Input::KeyRoutedEventArgs const &e) {
if (e.Key() == Windows::System::VirtualKey::Enter) {
diff --git a/support/hololens/ServoApp/BrowserPage.h b/support/hololens/ServoApp/BrowserPage.h
index 048e39a6f1a..454baee9076 100644
--- a/support/hololens/ServoApp/BrowserPage.h
+++ b/support/hololens/ServoApp/BrowserPage.h
@@ -30,6 +30,7 @@ public:
void OnStopButtonClicked(IInspectable const &, RoutedEventArgs const &);
void OnHomeButtonClicked(IInspectable const &, RoutedEventArgs const &);
void OnDevtoolsButtonClicked(IInspectable const &, RoutedEventArgs const &);
+ void OnJSInputEdited(IInspectable const &, Input::KeyRoutedEventArgs const &);
void OnURLEdited(IInspectable const &, Input::KeyRoutedEventArgs const &);
void OnURLFocused(IInspectable const &);
void
diff --git a/support/hololens/ServoApp/BrowserPage.xaml b/support/hololens/ServoApp/BrowserPage.xaml
index e9f4f18c5e3..7f1f051a444 100644
--- a/support/hololens/ServoApp/BrowserPage.xaml
+++ b/support/hololens/ServoApp/BrowserPage.xaml
@@ -150,34 +150,41 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/support/hololens/ServoApp/Devtools/Client.cpp b/support/hololens/ServoApp/Devtools/Client.cpp
index c7d1b7cfc89..65fb51df892 100644
--- a/support/hololens/ServoApp/Devtools/Client.cpp
+++ b/support/hololens/ServoApp/Devtools/Client.cpp
@@ -42,6 +42,16 @@ void DevtoolsClient::Run() {
});
}
+void DevtoolsClient::Evaluate(hstring code) {
+ if (!code.empty() && mConsoleActor.has_value()) {
+ JsonObject out;
+ out.Insert(L"to", *mConsoleActor);
+ out.Insert(L"type", JsonValue::CreateStringValue(L"evaluateJSAsync"));
+ out.Insert(L"text", JsonValue::CreateStringValue(code));
+ Send(out);
+ }
+}
+
IAsyncAction DevtoolsClient::Loop() {
auto cancellation = co_await winrt::get_cancellation_token();
cancellation.callback([=] {
@@ -101,11 +111,12 @@ void DevtoolsClient::HandleMessage(JsonObject obj) {
if (tab.HasKey(L"actor")) {
// Attach to tab, and ask for cached messaged
JsonObject msg1;
+ mConsoleActor = tab.GetNamedValue(L"consoleActor");
msg1.Insert(L"to", tab.GetNamedValue(L"actor"));
msg1.Insert(L"type", JsonValue::CreateStringValue(L"attach"));
Send(msg1);
JsonObject msg2;
- msg2.Insert(L"to", tab.GetNamedValue(L"consoleActor"));
+ msg2.Insert(L"to", *mConsoleActor);
msg2.Insert(L"type",
JsonValue::CreateStringValue(L"getCachedMessages"));
JsonArray types;
@@ -116,6 +127,12 @@ void DevtoolsClient::HandleMessage(JsonObject obj) {
return;
}
}
+ } else if (obj.HasKey(L"resultID")) {
+ // evaluateJSAsync response.
+ if (obj.GetNamedString(L"type", L"") == L"evaluationResult") {
+ HandleEvaluationResult(obj);
+ }
+ return;
} else if (obj.HasKey(L"type")) { // Not from root
if (obj.GetNamedString(L"type") == L"pageError") {
// Got a page error
@@ -196,6 +213,29 @@ void DevtoolsClient::HandlePageError(JsonObject message) {
mDelegate.OnDevtoolsMessage(level, source, body);
}
+void DevtoolsClient::HandleEvaluationResult(JsonObject message) {
+ auto level = DevtoolsMessageLevel::None;
+ hstring body = L"";
+ if (message.HasKey(L"result")) {
+ auto value = message.GetNamedValue(L"result");
+ if (value.ValueType() == JsonValueType::Object) {
+ auto type = value.GetObject().GetNamedString(L"type");
+ if (type == L"undefined") {
+ body = L"undefined";
+ } else {
+ body = L"