1- import type { INode } from '@sentry-internal/rrweb-snapshot' ;
1+ import { record } from '@sentry-internal/rrweb' ;
2+ import type { serializedElementNodeWithId , serializedNodeWithId } from '@sentry-internal/rrweb-snapshot' ;
23import { NodeType } from '@sentry-internal/rrweb-snapshot' ;
34import type { Breadcrumb } from '@sentry/types' ;
45import { htmlTreeAsString } from '@sentry/utils' ;
@@ -49,28 +50,26 @@ export const handleDomListener: (replay: ReplayContainer) => (handlerData: DomHa
4950} ;
5051
5152/** Get the base DOM breadcrumb. */
52- export function getBaseDomBreadcrumb ( target : Node | INode | null , message : string ) : Breadcrumb {
53- // `__sn` property is the serialized node created by rrweb
54- const serializedNode = target && isRrwebNode ( target ) && target . __sn . type === NodeType . Element ? target . __sn : null ;
53+ export function getBaseDomBreadcrumb ( target : Node | null , message : string ) : Breadcrumb {
54+ const nodeId = record . mirror . getId ( target ) ;
55+ const node = nodeId && record . mirror . getNode ( nodeId ) ;
56+ const meta = node && record . mirror . getMeta ( node ) ;
57+ const element = meta && isElement ( meta ) ? meta : null ;
5558
5659 return {
5760 message,
58- data : serializedNode
61+ data : element
5962 ? {
60- nodeId : serializedNode . id ,
63+ nodeId,
6164 node : {
62- id : serializedNode . id ,
63- tagName : serializedNode . tagName ,
64- textContent : target
65- ? Array . from ( target . childNodes )
66- . map (
67- ( node : Node | INode ) => '__sn' in node && node . __sn . type === NodeType . Text && node . __sn . textContent ,
68- )
69- . filter ( Boolean ) // filter out empty values
70- . map ( text => ( text as string ) . trim ( ) )
71- . join ( '' )
72- : '' ,
73- attributes : getAttributesToRecord ( serializedNode . attributes ) ,
65+ id : nodeId ,
66+ tagName : element . tagName ,
67+ textContent : Array . from ( element . childNodes )
68+ . map ( ( node : serializedNodeWithId ) => node . type === NodeType . Text && node . textContent )
69+ . filter ( Boolean ) // filter out empty values
70+ . map ( text => ( text as string ) . trim ( ) )
71+ . join ( '' ) ,
72+ attributes : getAttributesToRecord ( element . attributes ) ,
7473 } ,
7574 }
7675 : { } ,
@@ -90,11 +89,11 @@ export function handleDom(handlerData: DomHandlerData): Breadcrumb | null {
9089 } ) ;
9190}
9291
93- function getDomTarget ( handlerData : DomHandlerData ) : { target : Node | INode | null ; message : string } {
92+ function getDomTarget ( handlerData : DomHandlerData ) : { target : Node | null ; message : string } {
9493 const isClick = handlerData . name === 'click' ;
9594
9695 let message : string | undefined ;
97- let target : Node | INode | null = null ;
96+ let target : Node | null = null ;
9897
9998 // Accessing event.target can throw (see getsentry/raven-js#838, #768)
10099 try {
@@ -107,6 +106,6 @@ function getDomTarget(handlerData: DomHandlerData): { target: Node | INode | nul
107106 return { target, message } ;
108107}
109108
110- function isRrwebNode ( node : EventTarget ) : node is INode {
111- return '__sn' in node ;
109+ function isElement ( node : serializedNodeWithId ) : node is serializedElementNodeWithId {
110+ return node . type === NodeType . Element ;
112111}
0 commit comments