@@ -149,6 +149,13 @@ function isSVGElement(el: Element): boolean {
149
149
return el . tagName === 'svg' || el instanceof SVGElement ;
150
150
}
151
151
152
+ function getHref ( ) {
153
+ // return a href without hash
154
+ const a = document . createElement ( 'a' ) ;
155
+ a . href = '' ;
156
+ return a . href ;
157
+ }
158
+
152
159
export function transformAttribute (
153
160
doc : Document ,
154
161
name : string ,
@@ -160,7 +167,7 @@ export function transformAttribute(
160
167
} else if ( name === 'srcset' && value ) {
161
168
return getAbsoluteSrcsetString ( doc , value ) ;
162
169
} else if ( name === 'style' && value ) {
163
- return absoluteToStylesheet ( value , location . href ) ;
170
+ return absoluteToStylesheet ( value , getHref ( ) ) ;
164
171
} else {
165
172
return value ;
166
173
}
@@ -262,7 +269,7 @@ function serializeNode(
262
269
( n as HTMLStyleElement ) . sheet as CSSStyleSheet ,
263
270
) ;
264
271
if ( cssText ) {
265
- attributes . _cssText = absoluteToStylesheet ( cssText , location . href ) ;
272
+ attributes . _cssText = absoluteToStylesheet ( cssText , getHref ( ) ) ;
266
273
}
267
274
}
268
275
// form fields
@@ -335,7 +342,7 @@ function serializeNode(
335
342
let textContent = ( n as Text ) . textContent ;
336
343
const isStyle = parentTagName === 'STYLE' ? true : undefined ;
337
344
if ( isStyle && textContent ) {
338
- textContent = absoluteToStylesheet ( textContent , location . href ) ;
345
+ textContent = absoluteToStylesheet ( textContent , getHref ( ) ) ;
339
346
}
340
347
if ( parentTagName === 'SCRIPT' ) {
341
348
textContent = 'SCRIPT_PLACEHOLDER' ;
0 commit comments