Skip to content

Commit c7f4c36

Browse files
committed
fix href value
1 parent c1c687a commit c7f4c36

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/snapshot.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,13 @@ function isSVGElement(el: Element): boolean {
149149
return el.tagName === 'svg' || el instanceof SVGElement;
150150
}
151151

152+
function getHref() {
153+
// return a href without hash
154+
const a = document.createElement('a');
155+
a.href = '';
156+
return a.href;
157+
}
158+
152159
export function transformAttribute(
153160
doc: Document,
154161
name: string,
@@ -160,7 +167,7 @@ export function transformAttribute(
160167
} else if (name === 'srcset' && value) {
161168
return getAbsoluteSrcsetString(doc, value);
162169
} else if (name === 'style' && value) {
163-
return absoluteToStylesheet(value, location.href);
170+
return absoluteToStylesheet(value, getHref());
164171
} else {
165172
return value;
166173
}
@@ -262,7 +269,7 @@ function serializeNode(
262269
(n as HTMLStyleElement).sheet as CSSStyleSheet,
263270
);
264271
if (cssText) {
265-
attributes._cssText = absoluteToStylesheet(cssText, location.href);
272+
attributes._cssText = absoluteToStylesheet(cssText, getHref());
266273
}
267274
}
268275
// form fields
@@ -335,7 +342,7 @@ function serializeNode(
335342
let textContent = (n as Text).textContent;
336343
const isStyle = parentTagName === 'STYLE' ? true : undefined;
337344
if (isStyle && textContent) {
338-
textContent = absoluteToStylesheet(textContent, location.href);
345+
textContent = absoluteToStylesheet(textContent, getHref());
339346
}
340347
if (parentTagName === 'SCRIPT') {
341348
textContent = 'SCRIPT_PLACEHOLDER';

0 commit comments

Comments
 (0)