@@ -414,13 +414,32 @@ function handleMouseOver(event: MouseEvent) {
414
414
try {
415
415
const xpath = getXPath ( targetElement ) ;
416
416
// console.log('XPath of target element:', xpath);
417
- const elementToHighlight = document . evaluate (
417
+ let elementToHighlight : HTMLElement | null = document . evaluate (
418
418
xpath ,
419
419
document ,
420
420
null ,
421
421
XPathResult . FIRST_ORDERED_NODE_TYPE ,
422
422
null
423
- ) . singleNodeValue as HTMLElement ;
423
+ ) . singleNodeValue as HTMLElement | null ;
424
+ if ( ! elementToHighlight ) {
425
+ const enhancedSelector = getEnhancedCSSSelector ( targetElement , xpath ) ;
426
+ console . log ( 'CSS Selector:' , enhancedSelector ) ;
427
+ const elements = document . querySelectorAll < HTMLElement > ( enhancedSelector ) ;
428
+
429
+ // Try to find the element under the mouse
430
+ for ( const el of elements ) {
431
+ const rect = el . getBoundingClientRect ( ) ;
432
+ if (
433
+ event . clientX >= rect . left &&
434
+ event . clientX <= rect . right &&
435
+ event . clientY >= rect . top &&
436
+ event . clientY <= rect . bottom
437
+ ) {
438
+ elementToHighlight = el ;
439
+ break ;
440
+ }
441
+ }
442
+ }
424
443
if ( elementToHighlight ) {
425
444
const rect = elementToHighlight . getBoundingClientRect ( ) ;
426
445
const highlightOverlay = document . createElement ( 'div' ) ;
0 commit comments