@midscene/recorder 0.24.2-beta-20250730081235.0 → 0.24.2-beta-20250730123854.0
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/recorder-iife.js +43 -36
- package/package.json +2 -2
package/dist/recorder-iife.js
CHANGED
|
@@ -521,6 +521,7 @@
|
|
|
521
521
|
getNodeFromCacheList: ()=>getNodeFromCacheList,
|
|
522
522
|
getNodeInfoByXpath: ()=>getNodeInfoByXpath,
|
|
523
523
|
getXpathsById: ()=>getXpathsById,
|
|
524
|
+
getXpathsByPoint: ()=>getXpathsByPoint,
|
|
524
525
|
isNotContainerElement: ()=>isNotContainerElement,
|
|
525
526
|
setNodeHashCacheListOnWindow: ()=>setNodeHashCacheListOnWindow,
|
|
526
527
|
traverseTree: ()=>traverseTree,
|
|
@@ -651,6 +652,9 @@ ${indentStr}${after}`;
|
|
|
651
652
|
function isAElement(node) {
|
|
652
653
|
return node instanceof HTMLElement && "a" === node.tagName.toLowerCase();
|
|
653
654
|
}
|
|
655
|
+
function isSvgElement(node) {
|
|
656
|
+
return node instanceof SVGElement;
|
|
657
|
+
}
|
|
654
658
|
function isImgElement(node) {
|
|
655
659
|
if (!includeBaseElement(node) && node instanceof Element) {
|
|
656
660
|
const computedStyle = window.getComputedStyle(node);
|
|
@@ -1235,7 +1239,7 @@ ${indentStr}${after}`;
|
|
|
1235
1239
|
height: maxBottom - minTop
|
|
1236
1240
|
};
|
|
1237
1241
|
}
|
|
1238
|
-
var
|
|
1242
|
+
var getElementXpathIndex = (element)=>{
|
|
1239
1243
|
let index = 1;
|
|
1240
1244
|
let prev = element.previousElementSibling;
|
|
1241
1245
|
while(prev){
|
|
@@ -1244,30 +1248,31 @@ ${indentStr}${after}`;
|
|
|
1244
1248
|
}
|
|
1245
1249
|
return index;
|
|
1246
1250
|
};
|
|
1247
|
-
var
|
|
1248
|
-
|
|
1249
|
-
|
|
1250
|
-
while(current){
|
|
1251
|
-
if (current.nodeType === Node.TEXT_NODE) index++;
|
|
1252
|
-
current = current.previousSibling;
|
|
1253
|
-
}
|
|
1254
|
-
return index;
|
|
1251
|
+
var normalizeXpathText = (text)=>{
|
|
1252
|
+
if ("string" != typeof text) return "";
|
|
1253
|
+
return text.replace(/\s+/g, " ").trim();
|
|
1255
1254
|
};
|
|
1256
|
-
var
|
|
1257
|
-
|
|
1258
|
-
const
|
|
1259
|
-
|
|
1260
|
-
|
|
1255
|
+
var buildCurrentElementXpath = (element, isOrderSensitive, isLeafElement)=>{
|
|
1256
|
+
const parentPath = element.parentNode ? getElementXpath(element.parentNode, isOrderSensitive) : "";
|
|
1257
|
+
const prefix = parentPath ? `${parentPath}/` : "/";
|
|
1258
|
+
const tagName = element.nodeName.toLowerCase();
|
|
1259
|
+
const textContent = element.textContent?.trim();
|
|
1260
|
+
if (isOrderSensitive) {
|
|
1261
|
+
const index2 = getElementXpathIndex(element);
|
|
1262
|
+
return `${prefix}${tagName}[${index2}]`;
|
|
1263
|
+
}
|
|
1264
|
+
if (isLeafElement && textContent) return `${prefix}${tagName}[normalize-space()="${normalizeXpathText(textContent)}"]`;
|
|
1265
|
+
const index = getElementXpathIndex(element);
|
|
1266
|
+
return `${prefix}${tagName}[${index}]`;
|
|
1261
1267
|
};
|
|
1262
|
-
var
|
|
1268
|
+
var getElementXpath = (element, isOrderSensitive = false, isLeafElement = false)=>{
|
|
1263
1269
|
if (element.nodeType === Node.TEXT_NODE) {
|
|
1264
1270
|
const parentNode = element.parentNode;
|
|
1265
1271
|
if (parentNode && parentNode.nodeType === Node.ELEMENT_NODE) {
|
|
1266
|
-
const
|
|
1267
|
-
const textIndex = getTextNodeIndex(element);
|
|
1272
|
+
const parentXPath = getElementXpath(parentNode, isOrderSensitive, true);
|
|
1268
1273
|
const textContent = element.textContent?.trim();
|
|
1269
|
-
if (textContent) return `${
|
|
1270
|
-
return `${
|
|
1274
|
+
if (textContent) return `${parentXPath}/text()[normalize-space()="${normalizeXpathText(textContent)}"]`;
|
|
1275
|
+
return `${parentXPath}/text()`;
|
|
1271
1276
|
}
|
|
1272
1277
|
return "";
|
|
1273
1278
|
}
|
|
@@ -1275,29 +1280,31 @@ ${indentStr}${after}`;
|
|
|
1275
1280
|
const el = element;
|
|
1276
1281
|
if (el === document.documentElement) return "/html";
|
|
1277
1282
|
if (el === document.body) return "/html/body";
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1283
|
+
if (isSvgElement(el)) {
|
|
1284
|
+
let parent = el.parentNode;
|
|
1285
|
+
while(parent && parent.nodeType === Node.ELEMENT_NODE){
|
|
1286
|
+
if (!isSvgElement(parent)) return getElementXpath(parent, isOrderSensitive, isLeafElement);
|
|
1287
|
+
parent = parent.parentNode;
|
|
1288
|
+
}
|
|
1289
|
+
return getElementXpath(el.parentNode, isOrderSensitive, isLeafElement);
|
|
1284
1290
|
}
|
|
1285
|
-
|
|
1286
|
-
const index = getElementIndex(el);
|
|
1287
|
-
const baseXPath = `${parentXPath}/${tagName}[${index}]`;
|
|
1288
|
-
return addTextContentToXPath(el, baseXPath);
|
|
1291
|
+
return buildCurrentElementXpath(el, isOrderSensitive, isLeafElement);
|
|
1289
1292
|
};
|
|
1290
|
-
function
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
+
function getXpathsById(id) {
|
|
1294
|
+
const node = getNodeFromCacheList(id);
|
|
1295
|
+
if (!node) return null;
|
|
1296
|
+
const fullXPath = getElementXpath(node, false, true);
|
|
1293
1297
|
return [
|
|
1294
1298
|
fullXPath
|
|
1295
1299
|
];
|
|
1296
1300
|
}
|
|
1297
|
-
function
|
|
1298
|
-
const
|
|
1299
|
-
if (!
|
|
1300
|
-
|
|
1301
|
+
function getXpathsByPoint(point, isOrderSensitive) {
|
|
1302
|
+
const element = document.elementFromPoint(point.left, point.top);
|
|
1303
|
+
if (!element) return null;
|
|
1304
|
+
const fullXPath = getElementXpath(element, isOrderSensitive, true);
|
|
1305
|
+
return [
|
|
1306
|
+
fullXPath
|
|
1307
|
+
];
|
|
1301
1308
|
}
|
|
1302
1309
|
function getNodeInfoByXpath(xpath) {
|
|
1303
1310
|
const xpathResult = document.evaluate(xpath, document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@midscene/recorder",
|
|
3
|
-
"version": "0.24.2-beta-
|
|
3
|
+
"version": "0.24.2-beta-20250730123854.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
"antd": "^5.21.6",
|
|
25
25
|
"dayjs": "^1.11.11",
|
|
26
26
|
"react-dom": "18.3.1",
|
|
27
|
-
"@midscene/shared": "0.24.2-beta-
|
|
27
|
+
"@midscene/shared": "0.24.2-beta-20250730123854.0"
|
|
28
28
|
},
|
|
29
29
|
"peerDependencies": {
|
|
30
30
|
"react": "18.3.1",
|