CEFInject: Scope js injection

pull/239/head
Peter Repukat 1 year ago
parent f68e3070d0
commit cf23edafdb

@ -69,6 +69,11 @@ namespace CEFInject
nlohmann::json 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)
{ {
return InjectJs_Unscoped(tabname, L"(function(){\n" + js + L"\n})()", port);
}
nlohmann::json InjectJs_Unscoped(const std::wstring &tabname, const std::wstring &js, uint16_t port)
{
auto cli = internal::GetHttpClient(port); auto cli = internal::GetHttpClient(port);
if (auto res = cli.Get("/json")) { if (auto res = cli.Get("/json")) {
if (res->status == 200) { if (res->status == 200) {
@ -127,6 +132,5 @@ namespace CEFInject
} }
} }
return nullptr; return nullptr;
} }
} }

@ -32,5 +32,6 @@ namespace CEFInject
bool CEFDebugAvailable(uint16_t port = internal::port_); bool CEFDebugAvailable(uint16_t port = internal::port_);
std::vector<std::wstring> AvailableTabs(uint16_t port = internal::port_); std::vector<std::wstring> AvailableTabs(uint16_t port = internal::port_);
nlohmann::json InjectJs(const std::wstring& tabname, const std::wstring& js, uint16_t port = internal::port_); nlohmann::json InjectJs(const std::wstring& tabname, const std::wstring& js, uint16_t port = internal::port_);
nlohmann::json InjectJs_Unscoped(const std::wstring& tabname, const std::wstring& js, uint16_t port = internal::port_);
} }
Loading…
Cancel
Save