Skip to content

Commit 5c17dd5

Browse files
committed
Don't capture stylesheet Assets if they have a media attribute which is currently not in force
1 parent 9727908 commit 5c17dd5

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

packages/rrweb/src/record/observers/asset-manager.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,31 @@ export default class AssetManager {
138138
let url = sheetBaseHref; // linkEl.href for a link element
139139
if (styleId) {
140140
url += `#rr_style_el:${styleId}`;
141+
} else if (el.getAttribute('media') !== null) {
142+
const linkAppliedQuery = matchMedia(el.getAttribute('media') as string);
143+
if (!linkAppliedQuery.matches) {
144+
try {
145+
try {
146+
linkAppliedQuery.addEventListener(
147+
'change',
148+
() => this.captureStylesheet(sheetBaseHref, el, styleId),
149+
);
150+
} catch (e1) {
151+
// deprecated Safari method
152+
linkAppliedQuery.addListener(
153+
() => this.captureStylesheet(sheetBaseHref, el, styleId),
154+
);
155+
}
156+
return {
157+
url,
158+
status: 'media-mismatch',
159+
};
160+
} catch (e2) {
161+
// can't listen, go ahead and capture now
162+
}
163+
}
141164
}
165+
142166
try {
143167
cssRules = el.sheet!.cssRules;
144168
} catch (e) {

packages/types/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export type loadedEvent = {
2121

2222
export type assetStatus = {
2323
url: string;
24-
status: 'capturing' | 'captured' | 'error' | 'refused';
24+
status: 'capturing' | 'captured' | 'media-mismatch' | 'error' | 'refused';
2525
info?: string;
2626
timeout?: number;
2727
};

0 commit comments

Comments
 (0)