Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
app: Remove detected default OBS styles
This avoids having to explicitly tell people to remove these default styles, since the cause issues with the alignment of the overlays.
- Loading branch information
1 parent
35fcc3e
commit 39a37e7
Showing
2 changed files
with
44 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/** | ||
* The default browser source styles that OBS injects for a new browser source. | ||
* | ||
* We should remove these default since the margin auto will break alignment | ||
* for our overlays | ||
*/ | ||
const DEFAULT_STYLES = | ||
'body { background-color: rgba(0, 0, 0, 0); margin: 0px auto; overflow: hidden; }'; | ||
|
||
/** | ||
* Locate the style element containing the default OBS browser source styles | ||
*/ | ||
export const findDefaultOBSStlyeNode = () => | ||
Array.from(document.querySelectorAll('head style:not([data-emotion])')).find( | ||
el => el.innerHTML === DEFAULT_STYLES | ||
); | ||
|
||
export const ensureNoOBSDefaultStyles = () => { | ||
findDefaultOBSStlyeNode()?.remove(); | ||
|
||
const head = document.querySelector('head'); | ||
|
||
if (head === null) { | ||
return () => null; | ||
} | ||
const observer = new MutationObserver(() => { | ||
findDefaultOBSStlyeNode()?.remove(); | ||
}); | ||
|
||
observer.observe(head, {childList: true, attributes: false}); | ||
|
||
return () => observer.disconnect(); | ||
}; |
39a37e7
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: