@@ -168,7 +168,7 @@ class PageEventsRecorder {
168168 const time = new Date ( ) . toISOString ( ) ;
169169 const event = [ this . commandId , eventType , nodeId , relatedNodeId , time ] as IFocusEvent ;
170170 this . focusEvents . push ( event ) ;
171- this . checkForPropertyChanges ( time ) ;
171+ this . getPropertyChanges ( time , this . domChanges ) ;
172172 }
173173
174174 public trackMouse ( eventType : MouseEventType , mouseEvent : MouseEvent ) {
@@ -206,59 +206,8 @@ class PageEventsRecorder {
206206 this . uploadChanges ( ) ;
207207 }
208208
209- public checkForLocationChange ( changeTime ?: string ) {
210- const timestamp = changeTime || new Date ( ) . toISOString ( ) ;
211- const currentLocation = window . self . location . href ;
212- if ( this . location !== currentLocation ) {
213- this . location = currentLocation ;
214- this . domChanges . push ( [
215- this . commandId ,
216- 'location' ,
217- { id : - 1 , textContent : currentLocation } ,
218- timestamp ,
219- idx ( ) ,
220- ] ) ;
221- }
222- }
223-
224- public checkForStylesheetChanges ( changeTime ?: string ) {
225- const timestamp = changeTime || new Date ( ) . toISOString ( ) ;
226- for ( const [ style , current ] of this . stylesheets ) {
227- if ( ! style . sheet || ! style . isConnected ) continue ;
228- const sheet = style . sheet as CSSStyleSheet ;
229- const newPropValue = [ ...sheet . cssRules ] . map ( x => x . cssText ) ;
230- if ( newPropValue . toString ( ) !== current . toString ( ) ) {
231- const nodeId = nodeTracker . getId ( style ) ;
232- this . domChanges . push ( [
233- this . commandId ,
234- 'property' ,
235- { id : nodeId , properties : { 'sheet.cssRules' : newPropValue } } ,
236- timestamp ,
237- idx ( ) ,
238- ] ) ;
239- this . stylesheets . set ( style , newPropValue ) ;
240- }
241- }
242- }
243-
244- public checkForPropertyChanges ( changeTime ?: string ) {
245- const timestamp = changeTime || new Date ( ) . toISOString ( ) ;
246- for ( const [ input , propertyMap ] of this . propertyTrackingElements ) {
247- for ( const [ propertyName , value ] of propertyMap ) {
248- const newPropValue = input [ propertyName ] ;
249- if ( newPropValue !== value ) {
250- const nodeId = nodeTracker . getId ( input ) ;
251- this . domChanges . push ( [
252- this . commandId ,
253- 'property' ,
254- { id : nodeId , properties : { [ propertyName ] : newPropValue } } ,
255- timestamp ,
256- idx ( ) ,
257- ] ) ;
258- propertyMap . set ( propertyName , newPropValue ) ;
259- }
260- }
261- }
209+ public checkForAllPropertyChanges ( ) {
210+ this . getPropertyChanges ( new Date ( ) . toISOString ( ) , this . domChanges ) ;
262211 }
263212
264213 public get pageResultset ( ) : PageRecorderResultSet {
@@ -291,15 +240,50 @@ class PageEventsRecorder {
291240 }
292241 }
293242
294- private trackStylesheet ( element : HTMLLinkElement | HTMLStyleElement ) {
243+ private getLocationChange ( changeTime : string , changes : IDomChangeEvent [ ] ) {
244+ const timestamp = changeTime || new Date ( ) . toISOString ( ) ;
245+ const currentLocation = window . self . location . href ;
246+ if ( this . location !== currentLocation ) {
247+ this . location = currentLocation ;
248+ changes . push ( [
249+ this . commandId ,
250+ 'location' ,
251+ { id : - 1 , textContent : currentLocation } ,
252+ timestamp ,
253+ idx ( ) ,
254+ ] ) ;
255+ }
256+ }
257+
258+ private getPropertyChanges ( changeTime : string , changes : IDomChangeEvent [ ] ) {
259+ const timestamp = changeTime ;
260+ for ( const [ input , propertyMap ] of this . propertyTrackingElements ) {
261+ for ( const [ propertyName , value ] of propertyMap ) {
262+ const newPropValue = input [ propertyName ] ;
263+ if ( newPropValue !== value ) {
264+ const nodeId = nodeTracker . getId ( input ) ;
265+ changes . push ( [
266+ this . commandId ,
267+ 'property' ,
268+ { id : nodeId , properties : { [ propertyName ] : newPropValue } } ,
269+ timestamp ,
270+ idx ( ) ,
271+ ] ) ;
272+ propertyMap . set ( propertyName , newPropValue ) ;
273+ }
274+ }
275+ }
276+ }
277+
278+ private trackStylesheet ( element : HTMLStyleElement ) {
295279 if ( ! element || this . stylesheets . has ( element ) ) return ;
296280 if ( ! element . sheet ) return ;
297281
298- const shouldRecordInitialStyle = element . textContent || element instanceof HTMLStyleElement ;
282+ const shouldStoreCurrentStyleState = ! ! element . textContent ;
299283 if ( element . sheet instanceof CSSStyleSheet ) {
300284 try {
301285 // if there's style text, record the current state
302- const startingStyle = shouldRecordInitialStyle
286+ const startingStyle = shouldStoreCurrentStyleState
303287 ? [ ...element . sheet . cssRules ] . map ( x => x . cssText )
304288 : [ ] ;
305289 this . stylesheets . set ( element , startingStyle ) ;
@@ -309,6 +293,26 @@ class PageEventsRecorder {
309293 }
310294 }
311295
296+ private checkForStylesheetChanges ( changeTime : string , changes : IDomChangeEvent [ ] ) {
297+ const timestamp = changeTime || new Date ( ) . toISOString ( ) ;
298+ for ( const [ style , current ] of this . stylesheets ) {
299+ if ( ! style . sheet || ! style . isConnected ) continue ;
300+ const sheet = style . sheet as CSSStyleSheet ;
301+ const newPropValue = [ ...sheet . cssRules ] . map ( x => x . cssText ) ;
302+ if ( newPropValue . toString ( ) !== current . toString ( ) ) {
303+ const nodeId = nodeTracker . getId ( style ) ;
304+ changes . push ( [
305+ this . commandId ,
306+ 'property' ,
307+ { id : nodeId , properties : { 'sheet.cssRules' : newPropValue } } ,
308+ timestamp ,
309+ idx ( ) ,
310+ ] ) ;
311+ this . stylesheets . set ( style , newPropValue ) ;
312+ }
313+ }
314+ }
315+
312316 private onMutation ( mutations : MutationRecord [ ] ) {
313317 const changes = this . convertMutationsToChanges ( mutations ) ;
314318 this . domChanges . push ( ...changes ) ;
@@ -319,8 +323,8 @@ class PageEventsRecorder {
319323 const currentCommandId = this . commandId ;
320324 const stamp = new Date ( ) . toISOString ( ) ;
321325
322- this . checkForLocationChange ( stamp ) ;
323- this . checkForPropertyChanges ( stamp ) ;
326+ this . getLocationChange ( stamp , changes ) ;
327+ this . getPropertyChanges ( stamp , changes ) ;
324328
325329 const addedNodeMap = new Map < Node , INodeData > ( ) ;
326330 const removedNodes = new Set < Node > ( ) ;
@@ -411,7 +415,7 @@ class PageEventsRecorder {
411415 }
412416 }
413417
414- this . checkForStylesheetChanges ( stamp ) ;
418+ this . checkForStylesheetChanges ( stamp , changes ) ;
415419
416420 return changes ;
417421 }
@@ -451,10 +455,6 @@ class PageEventsRecorder {
451455 }
452456 changes . push ( [ currentCommandId , 'added' , serial , stamp , idx ( ) ] ) ;
453457 addedNodeMap . set ( node , serial ) ;
454- const childRecords = this . serializeChildren ( node , addedNodeMap ) ;
455- for ( const childData of childRecords ) {
456- changes . push ( [ currentCommandId , 'added' , childData , stamp , idx ( ) ] ) ;
457- }
458458 return serial ;
459459 }
460460
@@ -603,17 +603,17 @@ const perfObserver = new PerformanceObserver(() => {
603603} ) ;
604604perfObserver . observe ( { type : 'largest-contentful-paint' , buffered : true } ) ;
605605
606- document . addEventListener ( 'input' , ( ) => recorder . checkForPropertyChanges ( ) , {
606+ document . addEventListener ( 'input' , ( ) => recorder . checkForAllPropertyChanges ( ) , {
607607 capture : true ,
608608 passive : true ,
609609} ) ;
610610
611- document . addEventListener ( 'keydown' , ( ) => recorder . checkForPropertyChanges ( ) , {
611+ document . addEventListener ( 'keydown' , ( ) => recorder . checkForAllPropertyChanges ( ) , {
612612 capture : true ,
613613 passive : true ,
614614} ) ;
615615
616- document . addEventListener ( 'change' , ( ) => recorder . checkForPropertyChanges ( ) , {
616+ document . addEventListener ( 'change' , ( ) => recorder . checkForAllPropertyChanges ( ) , {
617617 capture : true ,
618618 passive : true ,
619619} ) ;
0 commit comments