diff --git a/browser-client.cpp b/browser-client.cpp index a53fe30da..e774efeb1 100644 --- a/browser-client.cpp +++ b/browser-client.cpp @@ -84,9 +84,10 @@ CefRefPtr BrowserClient::GetResourceRequestHandler( return nullptr; } -CefResourceRequestHandler::ReturnValue BrowserClient::OnBeforeResourceLoad( - CefRefPtr, CefRefPtr, CefRefPtr, - CefRefPtr) +CefResourceRequestHandler::ReturnValue +BrowserClient::OnBeforeResourceLoad(CefRefPtr, CefRefPtr, + CefRefPtr, + CefRefPtr) { return RV_CONTINUE; } @@ -679,6 +680,15 @@ void BrowserClient::OnLoadEnd(CefRefPtr, CefRefPtr frame, frame->ExecuteJavaScript(script, "", 0); } + + if (bs->javascript_active) { + std::string javascript; + javascript = bs->javascript; + if (!bs->javascript.empty()) + frame->ExecuteJavaScript(javascript, "", 0); + /*frame->ExecuteJavaScript(javascript, frame->GetURL(), + 0);*/ + } } bool BrowserClient::OnConsoleMessage(CefRefPtr, diff --git a/obs-browser-plugin.cpp b/obs-browser-plugin.cpp index 736f1b51b..93b1a4122 100644 --- a/obs-browser-plugin.cpp +++ b/obs-browser-plugin.cpp @@ -132,6 +132,9 @@ static void browser_source_get_defaults(obs_data_t *settings) (int)DEFAULT_CONTROL_LEVEL); obs_data_set_default_string(settings, "css", default_css); obs_data_set_default_bool(settings, "reroute_audio", false); + + obs_data_set_default_string(settings, "javascript", ""); + obs_data_set_default_bool(settings, "javascript_active", false); } static bool is_local_file_modified(obs_properties_t *props, obs_property_t *, @@ -208,6 +211,17 @@ static obs_properties_t *browser_source_get_properties(void *data) obs_properties_add_bool(props, "restart_when_active", obs_module_text("RefreshBrowserActive")); + obs_property_t *j = obs_properties_add_text( + props, "javascript", obs_module_text("JavaScript"), + OBS_TEXT_MULTILINE); + obs_property_text_set_monospace(j, true); + + prop = obs_properties_add_bool(props, "javascript_active", + obs_module_text("JavaScriptActive")); + + obs_property_set_long_description( + j, obs_module_text("JavaScript.ToolTip")); + obs_property_t *controlLevel = obs_properties_add_list( props, "webpage_control_level", obs_module_text("WebpageControlLevel"), OBS_COMBO_TYPE_LIST, diff --git a/obs-browser-source.cpp b/obs-browser-source.cpp index 720ed268e..8519606d6 100644 --- a/obs-browser-source.cpp +++ b/obs-browser-source.cpp @@ -503,6 +503,8 @@ void BrowserSource::Update(obs_data_t *settings) ControlLevel n_webpage_control_level; std::string n_url; std::string n_css; + std::string n_javascript; + bool n_javascript_active; n_is_local = obs_data_get_bool(settings, "is_local_file"); n_width = (int)obs_data_get_int(settings, "width"); @@ -518,6 +520,9 @@ void BrowserSource::Update(obs_data_t *settings) n_webpage_control_level = static_cast( obs_data_get_int(settings, "webpage_control_level")); + n_javascript_active = obs_data_get_bool(settings, "javascript_active"); + n_javascript = obs_data_get_string(settings, "javascript"); + if (n_is_local && !n_url.empty()) { n_url = CefURIEncode(n_url, false); @@ -563,7 +568,9 @@ void BrowserSource::Update(obs_data_t *settings) n_fps == fps && n_shutdown == shutdown_on_invisible && n_restart == restart && n_css == css && n_url == url && n_reroute == reroute_audio && - n_webpage_control_level == webpage_control_level) { + n_webpage_control_level == webpage_control_level && + n_javascript_active == javascript_active && + n_javascript == javascript) { if (n_width == width && n_height == height) return; @@ -598,6 +605,9 @@ void BrowserSource::Update(obs_data_t *settings) css = n_css; url = n_url; + javascript = n_javascript; + javascript_active = n_javascript_active; + obs_source_set_audio_active(source, reroute_audio); } diff --git a/obs-browser-source.hpp b/obs-browser-source.hpp index 1ba1b47ab..96525ce5c 100644 --- a/obs-browser-source.hpp +++ b/obs-browser-source.hpp @@ -66,6 +66,8 @@ struct BrowserSource { std::string url; std::string css; + std::string javascript; + bool javascript_active = false; gs_texture_t *texture = nullptr; gs_texture_t *extra_texture = nullptr; uint32_t last_cx = 0;