File tree 5 files changed +114
-5
lines changed
web-integration/tests/unit-test
5 files changed +114
-5
lines changed Original file line number Diff line number Diff line change @@ -330,6 +330,19 @@ export function visibleRect(
330
330
331
331
// check if the element is hidden by an ancestor
332
332
let parent : HTMLElement | Node | null = el ;
333
+ const parentUntilNonStatic = ( currentNode : HTMLElement | Node | null ) => {
334
+ // find a parent element that is not static
335
+ let parent = currentNode ?. parentElement ;
336
+ while ( parent ) {
337
+ const style = currentWindow . getComputedStyle ( parent ) ;
338
+ if ( style . position !== 'static' ) {
339
+ return parent ;
340
+ }
341
+ parent = parent . parentElement ;
342
+ }
343
+ return null ;
344
+ } ;
345
+
333
346
while ( parent && parent !== currentDocument . body ) {
334
347
if ( ! ( parent instanceof currentWindow . HTMLElement ) ) {
335
348
parent = parent . parentElement ;
@@ -354,10 +367,15 @@ export function visibleRect(
354
367
}
355
368
}
356
369
// if the parent is a fixed element, stop the search
357
- if ( parentStyle . position === 'fixed' ) {
370
+ if ( parentStyle . position === 'fixed' || parentStyle . position === 'sticky' ) {
358
371
break ;
359
372
}
360
- parent = parent . parentElement ;
373
+
374
+ if ( parentStyle . position === 'absolute' ) {
375
+ parent = parentUntilNonStatic ( parent ) ;
376
+ } else {
377
+ parent = parent . parentElement ;
378
+ }
361
379
}
362
380
363
381
return {
Original file line number Diff line number Diff line change @@ -602,6 +602,20 @@ exports[`extractor > basic 1`] = `
602
602
},
603
603
" content" : " " ,
604
604
} ,
605
+ {
606
+ " attributes" : {
607
+ " htmlTagName" : " <div>" ,
608
+ " nodeType" : " TEXT Node" ,
609
+ },
610
+ " content" : " AAA" ,
611
+ } ,
612
+ {
613
+ " attributes" : {
614
+ " htmlTagName" : " <div>" ,
615
+ " nodeType" : " TEXT Node" ,
616
+ },
617
+ " content" : " This should be collected" ,
618
+ } ,
605
619
{
606
620
" attributes" : {
607
621
" htmlTagName" : " " ,
@@ -2938,6 +2952,72 @@ exports[`extractor > basic 2`] = `
2938
2952
" children" : [],
2939
2953
" node" : null ,
2940
2954
},
2955
+ {
2956
+ " children" : [
2957
+ {
2958
+ " children" : [],
2959
+ " node" : null ,
2960
+ },
2961
+ {
2962
+ " children" : [
2963
+ {
2964
+ " children" : [],
2965
+ " node" : {
2966
+ " attributes" : {
2967
+ " htmlTagName" : " <div>" ,
2968
+ " nodeType" : " TEXT Node" ,
2969
+ },
2970
+ " content" : " AAA" ,
2971
+ " indexId" : 78 ,
2972
+ },
2973
+ },
2974
+ ],
2975
+ " node" : null ,
2976
+ },
2977
+ {
2978
+ " children" : [],
2979
+ " node" : null ,
2980
+ },
2981
+ {
2982
+ " children" : [
2983
+ {
2984
+ " children" : [],
2985
+ " node" : null ,
2986
+ },
2987
+ ],
2988
+ " node" : null ,
2989
+ },
2990
+ {
2991
+ " children" : [],
2992
+ " node" : null ,
2993
+ },
2994
+ {
2995
+ " children" : [
2996
+ {
2997
+ " children" : [],
2998
+ " node" : {
2999
+ " attributes" : {
3000
+ " htmlTagName" : " <div>" ,
3001
+ " nodeType" : " TEXT Node" ,
3002
+ },
3003
+ " content" : " This should be collected" ,
3004
+ " indexId" : 79 ,
3005
+ },
3006
+ },
3007
+ ],
3008
+ " node" : null ,
3009
+ },
3010
+ {
3011
+ " children" : [],
3012
+ " node" : null ,
3013
+ },
3014
+ ],
3015
+ " node" : null ,
3016
+ },
3017
+ {
3018
+ " children" : [],
3019
+ " node" : null ,
3020
+ },
2941
3021
],
2942
3022
" node" : null ,
2943
3023
},
@@ -2957,7 +3037,7 @@ exports[`extractor > basic 2`] = `
2957
3037
" nodeType" : " TEXT Node" ,
2958
3038
},
2959
3039
" content" : " Child Page" ,
2960
- " indexId" : 79 ,
3040
+ " indexId" : 81 ,
2961
3041
},
2962
3042
},
2963
3043
],
@@ -2977,7 +3057,7 @@ exports[`extractor > basic 2`] = `
2977
3057
" nodeType" : " TEXT Node" ,
2978
3058
},
2979
3059
" content" : " This is a child page." ,
2980
- " indexId" : 80 ,
3060
+ " indexId" : 82 ,
2981
3061
},
2982
3062
},
2983
3063
],
@@ -2997,7 +3077,7 @@ exports[`extractor > basic 2`] = `
2997
3077
" nodeType" : " TEXT Node" ,
2998
3078
},
2999
3079
" content" : " Click me" ,
3000
- " indexId" : 81 ,
3080
+ " indexId" : 83 ,
3001
3081
},
3002
3082
},
3003
3083
],
Original file line number Diff line number Diff line change @@ -348,6 +348,17 @@ <h3>Form</h3>
348
348
< iframe src ="https://www.bytedance.com " frameborder ="0 " width ="400px " height ="200px "> </ iframe >
349
349
</ div >
350
350
</ div >
351
+
352
+
353
+ < div style ="overflow: hidden; width: 100px; height: 100px; background-color: #ccc; ">
354
+ < div style ="width: 120px; height: 120px; background-color: #EEE; "> AAA</ div >
355
+ < div style ="width: 120px; height: 120px; background-color: #EEE; "> BBB</ div >
356
+ < div style ="position: absolute; bottom: 200px; right: 0; width: 120px; height: 120px; background-color: #CCC; ">
357
+ This should be collected
358
+ </ div >
359
+
360
+
361
+ </ div >
351
362
</ body >
352
363
353
364
</ html >
You can’t perform that action at this time.
0 commit comments