From 57a2e140ea419f7790b1672529f21dfe2261b52b Mon Sep 17 00:00:00 2001 From: Francesco Novy Date: Fri, 13 Jan 2023 06:11:57 +0100 Subject: [PATCH] feat: Guard against missing `window.CSSStyleSheet` (#1088) --- packages/rrweb/src/record/observer.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/rrweb/src/record/observer.ts b/packages/rrweb/src/record/observer.ts index cfc17a7e..324342e1 100644 --- a/packages/rrweb/src/record/observer.ts +++ b/packages/rrweb/src/record/observer.ts @@ -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 (