@@ -15,16 +15,6 @@ function log( ...message ) {
15
15
console . log ( consoleLogPrefix , ...message ) ;
16
16
}
17
17
18
- /*
19
- * Observe the loading of embeds on the page. We need to run this now before the resources on the page have fully
20
- * loaded because we need to start observing the embed wrappers before the embeds have loaded. When we detect
21
- * subtree modifications in an embed wrapper, we then need to measure the new height of the wrapper element.
22
- * However, since there may be multiple subtree modifications performed as an embed is loaded, we need to wait until
23
- * what is likely the last mutation.
24
- * TODO: This is a magic number. Ideally we wouldn't need this.
25
- */
26
- const EMBED_LOAD_WAIT_MS = 5000 ;
27
-
28
18
/**
29
19
* Embed element heights.
30
20
*
@@ -69,7 +59,7 @@ export async function finalize( { urlMetric, isDebug } ) {
69
59
if ( loadedElementContentRects . has ( element . xpath ) ) {
70
60
if ( isDebug ) {
71
61
log (
72
- ' Overriding:' ,
62
+ ` Overriding boundingClientRect for ${ element . xpath } :` ,
73
63
element . boundingClientRect ,
74
64
'=>' ,
75
65
loadedElementContentRects . get ( element . xpath )
@@ -93,20 +83,9 @@ function monitorEmbedWrapperForResizes( embedWrapper ) {
93
83
throw new Error ( 'Embed wrapper missing data-od-xpath attribute.' ) ;
94
84
}
95
85
const xpath = embedWrapper . dataset . odXpath ;
96
- let timeoutId = 0 ;
97
86
const observer = new ResizeObserver ( ( entries ) => {
98
87
const [ entry ] = entries ;
99
- if ( timeoutId > 0 ) {
100
- clearTimeout ( timeoutId ) ;
101
- }
102
- log (
103
- `Pending embed height of ${ entry . contentRect . height } px for ${ xpath } `
104
- ) ;
105
88
loadedElementContentRects . set ( xpath , entry . contentRect ) ;
106
- // TODO: Is the timeout really needed? We can just keep updating the height of the element until the URL metrics are sent when the page closes.
107
- timeoutId = setTimeout ( ( ) => {
108
- observer . disconnect ( ) ;
109
- } , EMBED_LOAD_WAIT_MS ) ;
110
89
} ) ;
111
90
observer . observe ( embedWrapper , { box : 'content-box' } ) ;
112
91
}
0 commit comments