Skip to content

Commit

Permalink
fix: viewport interactive elements retrieval (#601)
Browse files Browse the repository at this point in the history
  • Loading branch information
adeprez authored Sep 7, 2024
1 parent 69200e3 commit 6d0b97e
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lavague-core/lavague/core/base_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,8 +482,8 @@ def js_wrap_function_call(fn: str):
const windowHeight = (window.innerHeight || document.documentElement.clientHeight);
const windowWidth = (window.innerWidth || document.documentElement.clientWidth);
return (function() {
function getInteractions(e, in_viewport, foreground_only) {
return (function(inViewport, foregroundOnly) {
function getInteractions(e) {
const tag = e.tagName.toLowerCase();
if (!e.checkVisibility() || e.hasAttribute('disabled') || e.hasAttribute('readonly')
|| (tag === 'input' && e.getAttribute('type') === 'hidden') || tag === 'body') {
Expand Down Expand Up @@ -524,7 +524,7 @@ def js_wrap_function_call(fn: str):
//evts.push('SCROLL');
}
if (in_viewport == true) {
if (inViewport) {
const rect = e.getBoundingClientRect();
let iframe = e.ownerDocument.defaultView.frameElement;
while (iframe) {
Expand All @@ -543,10 +543,10 @@ def js_wrap_function_call(fn: str):
if (elemCenter.x > windowWidth) return [];
if (elemCenter.y < 0) return [];
if (elemCenter.y > windowHeight) return [];
if (foreground_only !== true) return evts; // whenever to check for elements above
if (!foregroundOnly) return evts; // whenever to check for elements above
let pointContainer = document.elementFromPoint(elemCenter.x, elemCenter.y);
do {
if (pointContainer === element) return evts;
if (pointContainer === e) return evts;
if (pointContainer == null) return evts;
} while (pointContainer = pointContainer.parentNode);
return [];
Expand All @@ -558,7 +558,7 @@ def js_wrap_function_call(fn: str):
const results = {};
function traverse(node, xpath) {
if (node.nodeType === Node.ELEMENT_NODE) {
const interactions = getInteractions(node, arguments?.[0], arguments?.[1]);
const interactions = getInteractions(node);
if (interactions.length > 0) {
results[xpath] = interactions;
}
Expand Down Expand Up @@ -589,7 +589,7 @@ def js_wrap_function_call(fn: str):
}
traverse(document.body, '/html/body');
return results;
})();
})(arguments?.[0], arguments?.[1]);
"""

JS_WAIT_DOM_IDLE = """
Expand Down

0 comments on commit 6d0b97e

Please sign in to comment.