Skip to content

Commit 977b066

Browse files
committed
add cssSelector fallback
1 parent a47a226 commit 977b066

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

extension/src/entrypoints/content.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -414,13 +414,32 @@ function handleMouseOver(event: MouseEvent) {
414414
try {
415415
const xpath = getXPath(targetElement);
416416
// console.log('XPath of target element:', xpath);
417-
const elementToHighlight = document.evaluate(
417+
let elementToHighlight: HTMLElement | null = document.evaluate(
418418
xpath,
419419
document,
420420
null,
421421
XPathResult.FIRST_ORDERED_NODE_TYPE,
422422
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+
}
424443
if (elementToHighlight) {
425444
const rect = elementToHighlight.getBoundingClientRect();
426445
const highlightOverlay = document.createElement('div');

0 commit comments

Comments
 (0)