Skip to content

Commit

Permalink
chore: Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewpomeroy committed Dec 12, 2023
1 parent af1f452 commit 83c7af7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
4 changes: 2 additions & 2 deletions .changeset/smooth-papayas-boil.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
"rrweb-snapshot": patch
"rrweb": patch
'rrweb-snapshot': patch
'rrweb': patch
---

Capture stylesheets designated as `rel="preload"`
11 changes: 7 additions & 4 deletions packages/rrweb-snapshot/src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1175,12 +1175,15 @@ export function serializeNodeWithId(
}

// <link rel=stylesheet href=...>
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,
() => {
Expand Down
12 changes: 7 additions & 5 deletions packages/rrweb-snapshot/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -334,13 +334,15 @@ export function getInputType(element: HTMLElement): Lowercase<string> | 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;
}

0 comments on commit 83c7af7

Please sign in to comment.