@@ -128,14 +128,28 @@ export function escapeImportStatement(rule: CSSImportRule): string {
128128 return statement . join ( ' ' ) + ';' ;
129129}
130130
131+ /*
132+ * serialize the css rules from the .sheet property
133+ * for <link rel="stylesheet"> elements, this is the only way of getting the rules without a FETCH
134+ * for <style> elements, this is less preferable to looking at childNodes[0].textContent
135+ * (which will include vendor prefixed rules which may not be used or visible to the recorded browser,
136+ * but which might be needed by the replayer browser)
137+ * however, at snapshot time, we don't know whether the style element has suffered
138+ * any programmatic manipulation prior to the snapshot, in which case the .sheet would be more up to date
139+ */
131140export function stringifyStylesheet ( s : CSSStyleSheet ) : string | null {
132141 try {
133142 const rules = s . rules || s . cssRules ;
134143 if ( ! rules ) {
135144 return null ;
136145 }
146+ let sheetHref = s . href ;
147+ if ( ! sheetHref && s . ownerNode && s . ownerNode . ownerDocument ) {
148+ // an inline <style> element
149+ sheetHref = s . ownerNode . ownerDocument . location . href ;
150+ }
137151 const stringifiedRules = Array . from ( rules , ( rule : CSSRule ) =>
138- stringifyRule ( rule , s . href ) ,
152+ stringifyRule ( rule , sheetHref ) ,
139153 ) . join ( '' ) ;
140154 return fixBrowserCompatibilityIssuesInCSS ( stringifiedRules ) ;
141155 } catch ( error ) {
0 commit comments