@jarvis-agent/core 0.2.1 → 0.2.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent/browser/build-dom-tree.d.ts.map +1 -1
- package/dist/index.cjs +55 -121
- package/dist/index.cjs.map +1 -1
- package/dist/index.esm.js +55 -121
- package/dist/index.esm.js.map +1 -1
- package/package.json +1 -1
package/dist/index.esm.js
CHANGED
|
@@ -42522,30 +42522,19 @@ function run_build_dom_tree() {
|
|
|
42522
42522
|
/**
|
|
42523
42523
|
* Get clickable elements on the page
|
|
42524
42524
|
*
|
|
42525
|
-
* @param {*}
|
|
42525
|
+
* @param {*} doHighlightElements Is highlighted
|
|
42526
42526
|
* @param {*} includeAttributes [attr_names...]
|
|
42527
|
-
* @returns { element_str,
|
|
42527
|
+
* @returns { element_str, selector_map }
|
|
42528
42528
|
*/
|
|
42529
|
-
function get_clickable_elements(
|
|
42529
|
+
function get_clickable_elements(doHighlightElements = true, includeAttributes) {
|
|
42530
42530
|
window.clickable_elements = {};
|
|
42531
42531
|
computedStyleCache = new WeakMap();
|
|
42532
42532
|
document.querySelectorAll("[eko-user-highlight-id]").forEach(ele => ele.removeAttribute("eko-user-highlight-id"));
|
|
42533
|
-
let page_tree = build_dom_tree(
|
|
42533
|
+
let page_tree = build_dom_tree(doHighlightElements);
|
|
42534
42534
|
let element_tree = parse_node(page_tree);
|
|
42535
|
+
let selector_map = create_selector_map(element_tree);
|
|
42535
42536
|
let element_str = clickable_elements_to_string(element_tree, includeAttributes);
|
|
42536
|
-
|
|
42537
|
-
width: window.innerWidth || document.documentElement.clientWidth,
|
|
42538
|
-
height: window.innerHeight || document.documentElement.clientHeight,
|
|
42539
|
-
};
|
|
42540
|
-
if (markHighlightElements) {
|
|
42541
|
-
let selector_map = {};
|
|
42542
|
-
// selector_map = create_selector_map(element_tree);
|
|
42543
|
-
return { element_str, client_rect, selector_map };
|
|
42544
|
-
}
|
|
42545
|
-
else {
|
|
42546
|
-
let area_map = create_area_map(element_tree);
|
|
42547
|
-
return { element_str, client_rect, area_map };
|
|
42548
|
-
}
|
|
42537
|
+
return { element_str, selector_map };
|
|
42549
42538
|
}
|
|
42550
42539
|
function get_highlight_element(highlightIndex) {
|
|
42551
42540
|
let element = document.querySelector(`[eko-user-highlight-id="eko-highlight-${highlightIndex}"]`);
|
|
@@ -42644,13 +42633,12 @@ function run_build_dom_tree() {
|
|
|
42644
42633
|
process_node(element_tree);
|
|
42645
42634
|
return formatted_text.join('\n');
|
|
42646
42635
|
}
|
|
42647
|
-
function
|
|
42648
|
-
let
|
|
42636
|
+
function create_selector_map(element_tree) {
|
|
42637
|
+
let selector_map = {};
|
|
42649
42638
|
function process_node(node) {
|
|
42650
42639
|
if (node.tagName) {
|
|
42651
42640
|
if (node.highlightIndex != null) {
|
|
42652
|
-
|
|
42653
|
-
area_map[node.highlightIndex] = get_element_real_bounding_rect(element);
|
|
42641
|
+
selector_map[node.highlightIndex] = node;
|
|
42654
42642
|
}
|
|
42655
42643
|
for (let i = 0; i < node.children.length; i++) {
|
|
42656
42644
|
process_node(node.children[i]);
|
|
@@ -42658,38 +42646,7 @@ function run_build_dom_tree() {
|
|
|
42658
42646
|
}
|
|
42659
42647
|
}
|
|
42660
42648
|
process_node(element_tree);
|
|
42661
|
-
return
|
|
42662
|
-
}
|
|
42663
|
-
function get_element_real_bounding_rect(element) {
|
|
42664
|
-
if (!element || !(element instanceof Element)) {
|
|
42665
|
-
return { x: 0, y: 0, width: 0, height: 0 };
|
|
42666
|
-
}
|
|
42667
|
-
let rect = element.getBoundingClientRect();
|
|
42668
|
-
let x = rect.left;
|
|
42669
|
-
let y = rect.top;
|
|
42670
|
-
let width = rect.width;
|
|
42671
|
-
let height = rect.height;
|
|
42672
|
-
let win = element.ownerDocument.defaultView;
|
|
42673
|
-
let maxDepth = 10;
|
|
42674
|
-
let depth = 0;
|
|
42675
|
-
while (win && win !== win.parent && depth < maxDepth) {
|
|
42676
|
-
depth++;
|
|
42677
|
-
const frameElement = win.frameElement;
|
|
42678
|
-
if (!frameElement) {
|
|
42679
|
-
break;
|
|
42680
|
-
}
|
|
42681
|
-
const frameRect = frameElement.getBoundingClientRect();
|
|
42682
|
-
x += frameRect.left;
|
|
42683
|
-
y += frameRect.top;
|
|
42684
|
-
// Consider the border and padding of the iframe.
|
|
42685
|
-
const frameStyle = getCachedComputedStyle(frameElement);
|
|
42686
|
-
x += parseFloat(frameStyle.borderLeftWidth) || 0;
|
|
42687
|
-
y += parseFloat(frameStyle.borderTopWidth) || 0;
|
|
42688
|
-
x += parseFloat(frameStyle.paddingLeft) || 0;
|
|
42689
|
-
y += parseFloat(frameStyle.paddingTop) || 0;
|
|
42690
|
-
win = win.parent;
|
|
42691
|
-
}
|
|
42692
|
-
return { x, y, width, height };
|
|
42649
|
+
return selector_map;
|
|
42693
42650
|
}
|
|
42694
42651
|
function parse_node(node_data, parent) {
|
|
42695
42652
|
if (!node_data) {
|
|
@@ -42729,9 +42686,8 @@ function run_build_dom_tree() {
|
|
|
42729
42686
|
}
|
|
42730
42687
|
return element_node;
|
|
42731
42688
|
}
|
|
42732
|
-
function build_dom_tree(
|
|
42689
|
+
function build_dom_tree(doHighlightElements) {
|
|
42733
42690
|
let highlightIndex = 0; // Reset highlight index
|
|
42734
|
-
let duplicates = new Set();
|
|
42735
42691
|
function highlightElement(element, index, parentIframe = null) {
|
|
42736
42692
|
// Create or get highlight container
|
|
42737
42693
|
let container = document.getElementById('eko-highlight-container');
|
|
@@ -42930,36 +42886,13 @@ function run_build_dom_tree() {
|
|
|
42930
42886
|
interactiveRoles.has(ariaRole) ||
|
|
42931
42887
|
(tabIndex !== null && tabIndex !== '-1') ||
|
|
42932
42888
|
element.getAttribute('data-action') === 'a-dropdown-select' ||
|
|
42933
|
-
element.getAttribute('data-action') === 'a-dropdown-button'
|
|
42934
|
-
element.getAttribute('contenteditable') === 'true';
|
|
42889
|
+
element.getAttribute('data-action') === 'a-dropdown-button';
|
|
42935
42890
|
if (hasInteractiveRole)
|
|
42936
42891
|
return true;
|
|
42937
|
-
//
|
|
42938
|
-
|
|
42939
|
-
//
|
|
42940
|
-
|
|
42941
|
-
// 'touchstart',
|
|
42942
|
-
// 'touchend',
|
|
42943
|
-
// 'keydown',
|
|
42944
|
-
// 'keyup',
|
|
42945
|
-
// 'focus',
|
|
42946
|
-
// 'blur',
|
|
42947
|
-
// ];
|
|
42948
|
-
const clickEventTypes = [
|
|
42949
|
-
'click',
|
|
42950
|
-
'mousedown',
|
|
42951
|
-
'mouseup',
|
|
42952
|
-
'touchstart',
|
|
42953
|
-
'touchend',
|
|
42954
|
-
];
|
|
42955
|
-
// Filter elements that have no real event listeners at all
|
|
42956
|
-
if (window.getEventListeners) {
|
|
42957
|
-
const listeners = window.getEventListeners(element);
|
|
42958
|
-
const hasRealClickListeners = clickEventTypes.some((type) => listeners[type]?.length > 0);
|
|
42959
|
-
if (!hasRealClickListeners) {
|
|
42960
|
-
return false;
|
|
42961
|
-
}
|
|
42962
|
-
}
|
|
42892
|
+
// Get computed style
|
|
42893
|
+
const style = getCachedComputedStyle(element);
|
|
42894
|
+
// Check if element has click-like styling
|
|
42895
|
+
const hasClickStyling = style.cursor === 'pointer' || element.style.cursor === 'pointer';
|
|
42963
42896
|
// Check for event listeners
|
|
42964
42897
|
const hasClickHandler = element.onclick !== null ||
|
|
42965
42898
|
element.getAttribute('onclick') !== null ||
|
|
@@ -42967,10 +42900,24 @@ function run_build_dom_tree() {
|
|
|
42967
42900
|
element.hasAttribute('@click') ||
|
|
42968
42901
|
element.hasAttribute('v-on:click');
|
|
42969
42902
|
// Helper function to safely get event listeners
|
|
42970
|
-
function
|
|
42903
|
+
function getEventListeners(el) {
|
|
42904
|
+
// if (window.getEventListeners) {
|
|
42905
|
+
// return window.getEventListeners?.(el) || {};
|
|
42906
|
+
// }
|
|
42971
42907
|
// List of common event types to check
|
|
42972
42908
|
const listeners = {};
|
|
42973
|
-
|
|
42909
|
+
const eventTypes = [
|
|
42910
|
+
'click',
|
|
42911
|
+
'mousedown',
|
|
42912
|
+
'mouseup',
|
|
42913
|
+
'touchstart',
|
|
42914
|
+
'touchend',
|
|
42915
|
+
'keydown',
|
|
42916
|
+
'keyup',
|
|
42917
|
+
'focus',
|
|
42918
|
+
'blur',
|
|
42919
|
+
];
|
|
42920
|
+
for (const type of eventTypes) {
|
|
42974
42921
|
const handler = el[`on${type}`];
|
|
42975
42922
|
if (handler) {
|
|
42976
42923
|
listeners[type] = [
|
|
@@ -42984,34 +42931,30 @@ function run_build_dom_tree() {
|
|
|
42984
42931
|
return listeners;
|
|
42985
42932
|
}
|
|
42986
42933
|
// Check for click-related events on the element itself
|
|
42987
|
-
const listeners =
|
|
42988
|
-
const hasClickListeners =
|
|
42934
|
+
const listeners = getEventListeners(element);
|
|
42935
|
+
const hasClickListeners = listeners &&
|
|
42936
|
+
(listeners.click?.length > 0 ||
|
|
42937
|
+
listeners.mousedown?.length > 0 ||
|
|
42938
|
+
listeners.mouseup?.length > 0 ||
|
|
42939
|
+
listeners.touchstart?.length > 0 ||
|
|
42940
|
+
listeners.touchend?.length > 0);
|
|
42989
42941
|
// Check for ARIA properties that suggest interactivity
|
|
42990
42942
|
const hasAriaProps = element.hasAttribute('aria-expanded') ||
|
|
42991
42943
|
element.hasAttribute('aria-pressed') ||
|
|
42992
42944
|
element.hasAttribute('aria-selected') ||
|
|
42993
42945
|
element.hasAttribute('aria-checked');
|
|
42946
|
+
// Check for form-related functionality
|
|
42947
|
+
element.form !== undefined ||
|
|
42948
|
+
element.hasAttribute('contenteditable') ||
|
|
42949
|
+
(style && style.userSelect !== 'none');
|
|
42994
42950
|
// Check if element is draggable
|
|
42995
42951
|
const isDraggable = element.draggable || element.getAttribute('draggable') === 'true';
|
|
42996
|
-
|
|
42997
|
-
|
|
42998
|
-
|
|
42999
|
-
|
|
43000
|
-
|
|
43001
|
-
|
|
43002
|
-
let count = 0;
|
|
43003
|
-
let current = element.parentElement;
|
|
43004
|
-
while (current && current !== document.documentElement) {
|
|
43005
|
-
hasClickStyling = current.style.cursor === 'pointer' || getCachedComputedStyle(current).cursor === 'pointer';
|
|
43006
|
-
if (hasClickStyling)
|
|
43007
|
-
return false;
|
|
43008
|
-
current = current.parentElement;
|
|
43009
|
-
if (++count > 10)
|
|
43010
|
-
break;
|
|
43011
|
-
}
|
|
43012
|
-
return true;
|
|
43013
|
-
}
|
|
43014
|
-
return false;
|
|
42952
|
+
return (hasAriaProps ||
|
|
42953
|
+
hasClickStyling ||
|
|
42954
|
+
hasClickHandler ||
|
|
42955
|
+
hasClickListeners ||
|
|
42956
|
+
// isFormRelated ||
|
|
42957
|
+
isDraggable);
|
|
43015
42958
|
}
|
|
43016
42959
|
// Helper function to check if element is visible
|
|
43017
42960
|
function isElementVisible(element) {
|
|
@@ -43041,14 +42984,11 @@ function run_build_dom_tree() {
|
|
|
43041
42984
|
if (!topEl)
|
|
43042
42985
|
return false;
|
|
43043
42986
|
// Check if the element or any of its parents match our target element
|
|
43044
|
-
let count = 0;
|
|
43045
42987
|
let current = topEl;
|
|
43046
42988
|
while (current && current !== shadowRoot) {
|
|
43047
42989
|
if (current === element)
|
|
43048
42990
|
return true;
|
|
43049
42991
|
current = current.parentElement;
|
|
43050
|
-
if (++count > 15)
|
|
43051
|
-
break;
|
|
43052
42992
|
}
|
|
43053
42993
|
return false;
|
|
43054
42994
|
}
|
|
@@ -43063,14 +43003,11 @@ function run_build_dom_tree() {
|
|
|
43063
43003
|
const topEl = document.elementFromPoint(point.x, point.y);
|
|
43064
43004
|
if (!topEl)
|
|
43065
43005
|
return false;
|
|
43066
|
-
let count = 0;
|
|
43067
43006
|
let current = topEl;
|
|
43068
43007
|
while (current && current !== document.documentElement) {
|
|
43069
43008
|
if (current === element)
|
|
43070
43009
|
return true;
|
|
43071
43010
|
current = current.parentElement;
|
|
43072
|
-
if (++count > 15)
|
|
43073
|
-
break;
|
|
43074
43011
|
}
|
|
43075
43012
|
return false;
|
|
43076
43013
|
}
|
|
@@ -43094,10 +43031,8 @@ function run_build_dom_tree() {
|
|
|
43094
43031
|
}
|
|
43095
43032
|
// Function to traverse the DOM and create nested JSON
|
|
43096
43033
|
function buildDomTree(node, parentIframe = null) {
|
|
43097
|
-
if (!node
|
|
43034
|
+
if (!node)
|
|
43098
43035
|
return null;
|
|
43099
|
-
}
|
|
43100
|
-
duplicates.add(node);
|
|
43101
43036
|
// Special case for text nodes
|
|
43102
43037
|
if (node.nodeType === Node.TEXT_NODE) {
|
|
43103
43038
|
const textContent = node.textContent.trim();
|
|
@@ -43142,7 +43077,7 @@ function run_build_dom_tree() {
|
|
|
43142
43077
|
if (shouldHighlight) {
|
|
43143
43078
|
nodeData.highlightIndex = highlightIndex++;
|
|
43144
43079
|
window.clickable_elements[nodeData.highlightIndex] = node;
|
|
43145
|
-
if (
|
|
43080
|
+
if (doHighlightElements) {
|
|
43146
43081
|
highlightElement(node, nodeData.highlightIndex, parentIframe);
|
|
43147
43082
|
}
|
|
43148
43083
|
}
|
|
@@ -43157,7 +43092,7 @@ function run_build_dom_tree() {
|
|
|
43157
43092
|
}
|
|
43158
43093
|
// Handle shadow DOM
|
|
43159
43094
|
if (node.shadowRoot) {
|
|
43160
|
-
const shadowChildren = Array.from(node.shadowRoot.
|
|
43095
|
+
const shadowChildren = Array.from(node.shadowRoot.childNodes).map((child) => buildDomTree(child, parentIframe));
|
|
43161
43096
|
nodeData.children.push(...shadowChildren);
|
|
43162
43097
|
}
|
|
43163
43098
|
// Handle iframes
|
|
@@ -43165,7 +43100,7 @@ function run_build_dom_tree() {
|
|
|
43165
43100
|
try {
|
|
43166
43101
|
const iframeDoc = node.contentDocument || node.contentWindow.document;
|
|
43167
43102
|
if (iframeDoc) {
|
|
43168
|
-
const iframeChildren = Array.from(iframeDoc.body.
|
|
43103
|
+
const iframeChildren = Array.from(iframeDoc.body.childNodes).map((child) => buildDomTree(child, node));
|
|
43169
43104
|
nodeData.children.push(...iframeChildren);
|
|
43170
43105
|
}
|
|
43171
43106
|
}
|
|
@@ -43174,9 +43109,8 @@ function run_build_dom_tree() {
|
|
|
43174
43109
|
}
|
|
43175
43110
|
}
|
|
43176
43111
|
else {
|
|
43177
|
-
|
|
43178
|
-
|
|
43179
|
-
const children = Array.from(node.children).map((child) => buildDomTree(child, parentIframe)).filter(child => child !== null);
|
|
43112
|
+
if (nodeData.isVisible != false) {
|
|
43113
|
+
const children = Array.from(node.childNodes).map((child) => buildDomTree(child, parentIframe));
|
|
43180
43114
|
nodeData.children.push(...children);
|
|
43181
43115
|
}
|
|
43182
43116
|
}
|