feat: Guard against missing window.CSSStyleSheet (#1088)

This commit is contained in:
Francesco Novy
2023-01-13 06:11:57 +01:00
committed by GitHub
parent 07aa1b2807
commit 57a2e140ea

View File

@@ -538,6 +538,13 @@ function initStyleSheetObserver(
{ styleSheetRuleCb, mirror, stylesheetManager }: observerParam,
{ win }: { win: IWindow },
): listenerHandler {
if (!win.CSSStyleSheet || !win.CSSStyleSheet.prototype) {
// If, for whatever reason, CSSStyleSheet is not available, we skip the observation of stylesheets.
return () => {
// Do nothing
};
}
// eslint-disable-next-line @typescript-eslint/unbound-method
const insertRule = win.CSSStyleSheet.prototype.insertRule;
win.CSSStyleSheet.prototype.insertRule = function (