diff --git a/.changeset/smooth-papayas-boil.md b/.changeset/smooth-papayas-boil.md
index aa733576ce..dcf4d36899 100644
--- a/.changeset/smooth-papayas-boil.md
+++ b/.changeset/smooth-papayas-boil.md
@@ -1,6 +1,6 @@
---
-"rrweb-snapshot": patch
-"rrweb": patch
+'rrweb-snapshot': patch
+'rrweb': patch
---
Capture stylesheets designated as `rel="preload"`
diff --git a/packages/rrweb-snapshot/src/snapshot.ts b/packages/rrweb-snapshot/src/snapshot.ts
index b955b047aa..75fd863e0b 100644
--- a/packages/rrweb-snapshot/src/snapshot.ts
+++ b/packages/rrweb-snapshot/src/snapshot.ts
@@ -1175,12 +1175,15 @@ export function serializeNodeWithId(
}
//
- if (serializedNode.type === NodeType.Element &&
+ if (
+ serializedNode.type === NodeType.Element &&
serializedNode.tagName === 'link' &&
typeof serializedNode.attributes.rel === 'string' &&
- (serializedNode.attributes.rel === 'stylesheet' || (serializedNode.attributes.rel === 'preload' &&
- typeof serializedNode.attributes.href === 'string' &&
- extractFileExtension(serializedNode.attributes.href) === 'css'))) {
+ (serializedNode.attributes.rel === 'stylesheet' ||
+ (serializedNode.attributes.rel === 'preload' &&
+ typeof serializedNode.attributes.href === 'string' &&
+ extractFileExtension(serializedNode.attributes.href) === 'css'))
+ ) {
onceStylesheetLoaded(
n as HTMLLinkElement,
() => {
diff --git a/packages/rrweb-snapshot/src/utils.ts b/packages/rrweb-snapshot/src/utils.ts
index d7d04f43ee..4d91a63f7b 100644
--- a/packages/rrweb-snapshot/src/utils.ts
+++ b/packages/rrweb-snapshot/src/utils.ts
@@ -334,13 +334,15 @@ export function getInputType(element: HTMLElement): Lowercase | null {
/**
* Extracts the file extension from an a path, considering search parameters and fragments.
- * @param path Path to file
- * @param [baseURL] Base URL of the page, used to resolve relative paths. Defaults to current page URL.
+ * @param path - Path to file
+ * @param baseURL - [optional] Base URL of the page, used to resolve relative paths. Defaults to current page URL.
*/
-export function extractFileExtension(path: string, baseURL?: string): string | null {
+export function extractFileExtension(
+ path: string,
+ baseURL?: string,
+): string | null {
const url = new URL(path, baseURL ?? window.location.href);
- const regex = /\.([0-9a-z]+)(?:[\?#]|$)/i;
+ const regex = /\.([0-9a-z]+)(?:[?#]|$)/i;
const match = url.pathname.match(regex);
- console.log(url.pathname)
return match?.[1] ?? null;
}