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

Avoid runtime error when CSSGroupingRule is not supported #693

Merged
Merged
Changes from all 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
11 changes: 10 additions & 1 deletion packages/rrweb/src/record/observer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ type WindowWithAngularZone = Window & {

export const mutationBuffers: MutationBuffer[] = [];

const isCSSGroupingRuleSupported = typeof CSSGroupingRule !== "undefined"

function getEventTarget(event: Event): EventTarget | null {
try {
if ('composedPath' in event) {
Expand Down Expand Up @@ -476,7 +478,7 @@ function initInputObserver(
function getNestedCSSRulePositions(rule: CSSRule): number[] {
const positions: number[] = [];
function recurse(childRule: CSSRule, pos: number[]) {
if (childRule.parentRule instanceof CSSGroupingRule) {
if (isCSSGroupingRuleSupported && childRule.parentRule instanceof CSSGroupingRule) {
const rules = Array.from(
(childRule.parentRule as CSSGroupingRule).cssRules,
);
Expand Down Expand Up @@ -520,6 +522,13 @@ function initStyleSheetObserver(
return deleteRule.apply(this, arguments);
};

if (!isCSSGroupingRuleSupported) {
return () => {
CSSStyleSheet.prototype.insertRule = insertRule;
CSSStyleSheet.prototype.deleteRule = deleteRule;
};
}

const groupingInsertRule = CSSGroupingRule.prototype.insertRule;
CSSGroupingRule.prototype.insertRule = function (
rule: string,
Expand Down