Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Ensure CSS support is checked more robustly #1106

Merged
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions packages/rrweb/src/record/observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,36 @@ type WindowWithAngularZone = IWindow & {
export const mutationBuffers: MutationBuffer[] = [];
export const processedNodeManager = new ProcessedNodeManager();

const isCSSGroupingRuleSupported = typeof CSSGroupingRule !== 'undefined';
const isCSSMediaRuleSupported = typeof CSSMediaRule !== 'undefined';
const isCSSSupportsRuleSupported = typeof CSSSupportsRule !== 'undefined';
const isCSSConditionRuleSupported = typeof CSSConditionRule !== 'undefined';
function isCSSStyleSheetMonkeyPatchable(
prop:
| 'CSSGroupingRule'
| 'CSSMediaRule'
| 'CSSSupportsRule'
| 'CSSConditionRule',
): boolean {
/* eslint-disable @typescript-eslint/ban-ts-comment,@typescript-eslint/unbound-method */
return Boolean(
typeof window[prop] !== 'undefined' &&
// Note: Generally, this check _shouldn't_ be necessary
// However, in some scenarios (e.g. jsdom) this can sometimes fail, so we check for it here
window[prop].prototype &&
// @ts-ignore ensure it is actually set
window[prop].prototype.insertRule &&
window[prop].prototype.deleteRule,
);
/* eslint-enable @typescript-eslint/ban-ts-comment,@typescript-eslint/unbound-method */
mydea marked this conversation as resolved.
Show resolved Hide resolved
}

const isCSSGroupingRuleSupported = isCSSStyleSheetMonkeyPatchable(
'CSSGroupingRule',
);
const isCSSMediaRuleSupported = isCSSStyleSheetMonkeyPatchable('CSSMediaRule');
const isCSSSupportsRuleSupported = isCSSStyleSheetMonkeyPatchable(
'CSSSupportsRule',
);
const isCSSConditionRuleSupported = isCSSStyleSheetMonkeyPatchable(
'CSSConditionRule',
);

// Event.path is non-standard and used in some older browsers
type NonStandardEvent = Omit<Event, 'composedPath'> & {
Expand Down