diff --git a/CEFInjectLib/CEFInject.cpp b/CEFInjectLib/CEFInject.cpp index c3a579d..c31d926 100644 --- a/CEFInjectLib/CEFInject.cpp +++ b/CEFInjectLib/CEFInject.cpp @@ -81,7 +81,7 @@ namespace CEFInject } - std::string InjectJs(const std::wstring& tabname, const std::wstring& js, uint16_t port) + nlohmann::json InjectJs(const std::wstring& tabname, const std::wstring& js, uint16_t port) { auto cli = internal::GetHttpClient(port); if (auto res = cli.Get("/json")) { @@ -98,7 +98,7 @@ namespace CEFInject rc = WSAStartup(MAKEWORD(2, 2), &wsaData); if (rc) { printf("WSAStartup Failed.\n"); - return {}; + return nullptr; } #endif @@ -116,13 +116,18 @@ namespace CEFInject {"expression", js} }} }.dump()); - std::string res; + nlohmann::json res = nullptr; + bool exit = false; while (ws->getReadyState() != easywsclient::WebSocket::CLOSED) { ws->poll(); - ws->dispatch([&ws, &res](const std::string& message) { - res = message; + ws->dispatch([&ws, & res, & exit](const std::string & message) { + res = nlohmann::json::parse(message)["result"]["result"]["value"]; + exit = true; }); - ws->close(); + if (exit) { + ws->close(); + return res; + } } #ifdef _WIN32 WSACleanup(); @@ -132,7 +137,7 @@ namespace CEFInject #ifdef _WIN32 WSACleanup(); #endif - return {}; + return nullptr; } } } diff --git a/CEFInjectLib/CEFInject.h b/CEFInjectLib/CEFInject.h index 82f4510..223fb65 100644 --- a/CEFInjectLib/CEFInject.h +++ b/CEFInjectLib/CEFInject.h @@ -27,6 +27,6 @@ namespace CEFInject bool CEFDebugAvailable(uint16_t port = 8080); std::vector AvailableTabs(uint16_t port = 8080); - std::string InjectJs(const std::wstring& tabname, const std::wstring& js, uint16_t port = 8080); + nlohmann::json InjectJs(const std::wstring& tabname, const std::wstring& js, uint16_t port = 8080); } \ No newline at end of file