Skip to content

Instantly share code, notes, and snippets.

@penbuvt
Last active August 8, 2024 06:19
Show Gist options
  • Select an option

  • Save penbuvt/d480e3f816e6d8ede47334ab57de369d to your computer and use it in GitHub Desktop.

Select an option

Save penbuvt/d480e3f816e6d8ede47334ab57de369d to your computer and use it in GitHub Desktop.
Patch to fix CSS not being injected by OBS browser sources on YouTube pop-out chat
diff --git a/browser-client.cpp b/browser-client.cpp
index 1c0ca26..09b6753 100644
--- a/browser-client.cpp
+++ b/browser-client.cpp
@@ -678,9 +678,11 @@ void BrowserClient::OnLoadEnd(CefRefPtr<CefBrowser>, CefRefPtr<CefFrame> frame,
CefURIEncode(bs->css, false).ToString();
std::string script;
+ script += "const innerHTMLPolicy = window.trustedTypes.createPolicy(" +
+ "'innerHTML', { createHTML: (html) => html });";
script += "const obsCSS = document.createElement('style');";
- script += "obsCSS.innerHTML = decodeURIComponent(\"" +
- uriEncodedCSS + "\");";
+ script += "obsCSS.innerHTML = innerHTMLPolicy.createHTML(" +
+ "decodeURIComponent(\"" + uriEncodedCSS + "\"));";
script += "document.querySelector('head').appendChild(obsCSS);";
frame->ExecuteJavaScript(script, "", 0);
@penbuvt
Copy link
Author

penbuvt commented Aug 8, 2024

This patch is the output of this stream: https://www.youtube.com/watch?v=F29oGpZSGsk

A similar patch has already been submitted to the obsproject/obs-browser repo: obsproject/obs-browser#449

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment