@midscene/web 0.5.2-beta-20241010035503.0 → 0.5.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.
@@ -876,7 +876,7 @@ var import_utils5 = require("@midscene/core/utils");
876
876
  var import_node_assert2 = __toESM(require("assert"));
877
877
  var import_core = __toESM(require("@midscene/core"));
878
878
  var import_utils3 = require("@midscene/core/utils");
879
- var import_img2 = require("@midscene/shared/img");
879
+ var import_img3 = require("@midscene/shared/img");
880
880
 
881
881
  // src/common/task-cache.ts
882
882
  var import_node_fs2 = require("fs");
@@ -889,8 +889,10 @@ var import_node_assert = __toESM(require("assert"));
889
889
  var import_node_crypto = require("crypto");
890
890
  var import_node_fs = require("fs");
891
891
  var import_node_path = __toESM(require("path"));
892
+ var import_constants = require("@midscene/shared/constants");
892
893
  var import_fs = require("@midscene/shared/fs");
893
894
  var import_img = require("@midscene/shared/img");
895
+ var import_img2 = require("@midscene/shared/img");
894
896
  var import_dayjs = __toESM(require_dayjs_min());
895
897
 
896
898
  // src/web-element.ts
@@ -901,7 +903,8 @@ var WebElementInfo = class {
901
903
  page,
902
904
  locator,
903
905
  id,
904
- attributes
906
+ attributes,
907
+ indexId
905
908
  }) {
906
909
  this.content = content;
907
910
  this.rect = rect;
@@ -913,6 +916,7 @@ var WebElementInfo = class {
913
916
  this.locator = locator;
914
917
  this.id = id;
915
918
  this.attributes = attributes;
919
+ this.indexId = indexId;
916
920
  }
917
921
  };
918
922
 
@@ -921,30 +925,35 @@ async function parseContextFromWebPage(page, _opt) {
921
925
  (0, import_node_assert.default)(page, "page is required");
922
926
  const url = page.url();
923
927
  const file = await page.screenshot();
924
- const screenshotBuffer = (0, import_node_fs.readFileSync)(file);
925
928
  const screenshotBase64 = (0, import_img.base64Encoded)(file);
926
929
  const captureElementSnapshot = await page.getElementInfos();
927
- const elementsInfo = await alignElements(
928
- screenshotBuffer,
929
- captureElementSnapshot,
930
- page
931
- );
930
+ const elementsInfo = await alignElements(captureElementSnapshot, page);
931
+ const elementsPositionInfoWithoutText = elementsInfo.filter((elementInfo) => {
932
+ if (elementInfo.attributes.nodeType === import_constants.NodeType.TEXT) {
933
+ return false;
934
+ }
935
+ return true;
936
+ });
932
937
  const size = await (0, import_img.imageInfoOfBase64)(screenshotBase64);
938
+ const screenshotBase64WithElementInfos = await (0, import_img2.compositeElementInfoImg)({
939
+ inputImgBase64: screenshotBase64.split(";base64,").pop(),
940
+ elementsPositionInfo: elementsPositionInfoWithoutText
941
+ });
933
942
  return {
934
943
  content: elementsInfo,
935
944
  size,
936
- screenshotBase64,
945
+ screenshotBase64: `data:image/png;base64,${screenshotBase64WithElementInfos}`,
937
946
  url
938
947
  };
939
948
  }
940
949
  var sizeThreshold = 3;
941
- async function alignElements(screenshotBuffer, elements, page) {
950
+ async function alignElements(elements, page) {
942
951
  const validElements = elements.filter((item) => {
943
952
  return item.rect.height >= sizeThreshold && item.rect.width >= sizeThreshold;
944
953
  });
945
954
  const textsAligned = [];
946
955
  for (const item of validElements) {
947
- const { rect, id, content, attributes, locator } = item;
956
+ const { rect, id, content, attributes, locator, indexId } = item;
948
957
  textsAligned.push(
949
958
  new WebElementInfo({
950
959
  rect,
@@ -952,7 +961,8 @@ async function alignElements(screenshotBuffer, elements, page) {
952
961
  id,
953
962
  content,
954
963
  attributes,
955
- page
964
+ page,
965
+ indexId
956
966
  })
957
967
  );
958
968
  }
@@ -1137,7 +1147,7 @@ var PageTaskExecutor = class {
1137
1147
  const item = {
1138
1148
  type: "screenshot",
1139
1149
  ts: Date.now(),
1140
- screenshot: (0, import_img2.base64Encoded)(file),
1150
+ screenshot: (0, import_img3.base64Encoded)(file),
1141
1151
  timing
1142
1152
  };
1143
1153
  return item;
@@ -1506,13 +1516,13 @@ var PageTaskExecutor = class {
1506
1516
  const assertTask = await this.convertPlanToExecutable([assertPlan]);
1507
1517
  await taskExecutor.append(this.wrapExecutorWithScreenshot(assertTask[0]));
1508
1518
  const output = await taskExecutor.flush();
1509
- if (output.pass) {
1519
+ if (output == null ? void 0 : output.pass) {
1510
1520
  return {
1511
1521
  output: void 0,
1512
1522
  executor: taskExecutor
1513
1523
  };
1514
1524
  }
1515
- errorThought = output.thought;
1525
+ errorThought = (output == null ? void 0 : output.thought) || "unknown error";
1516
1526
  const now = Date.now();
1517
1527
  if (now - startTime < checkIntervalMs) {
1518
1528
  const timeRemaining = checkIntervalMs - (now - startTime);
@@ -1655,11 +1665,11 @@ ${errorTask == null ? void 0 : errorTask.errorStack}`);
1655
1665
  // src/appium/page.ts
1656
1666
  var import_node_fs3 = __toESM(require("fs"));
1657
1667
  var import_utils7 = require("@midscene/core/utils");
1658
- var import_img3 = require("@midscene/shared/img");
1668
+ var import_img4 = require("@midscene/shared/img");
1659
1669
  var import_xmldom = require("@xmldom/xmldom");
1660
1670
 
1661
1671
  // src/extractor/web-extractor.ts
1662
- var import_constants = require("@midscene/shared/constants");
1672
+ var import_constants2 = require("@midscene/shared/constants");
1663
1673
 
1664
1674
  // src/extractor/util.ts
1665
1675
  var import_js_sha256 = __toESM(require_sha256());
@@ -1676,12 +1686,9 @@ function midsceneGenerateHash(content, rect) {
1676
1686
  const hashHex = (0, import_js_sha256.default)(combined);
1677
1687
  return hashHex.slice(0, 10);
1678
1688
  }
1679
- function generateId(numberId) {
1680
- return `${numberId}`;
1681
- }
1682
1689
 
1683
1690
  // src/extractor/constants.ts
1684
- var import_constants2 = require("@midscene/shared/constants");
1691
+ var import_constants3 = require("@midscene/shared/constants");
1685
1692
 
1686
1693
  // src/extractor/client-extractor.ts
1687
1694
  function getNodeAttributes2(node) {
@@ -1790,35 +1797,35 @@ function extractTextWithPosition2(initNode) {
1790
1797
  let nodeType;
1791
1798
  switch (node.nodeName.toUpperCase()) {
1792
1799
  case "TEXT":
1793
- nodeType = import_constants2.NodeType.TEXT;
1800
+ nodeType = import_constants3.NodeType.TEXT;
1794
1801
  break;
1795
1802
  case "IMAGE":
1796
- nodeType = import_constants2.NodeType.IMG;
1803
+ nodeType = import_constants3.NodeType.IMG;
1797
1804
  break;
1798
1805
  case "BUTTON":
1799
- nodeType = import_constants2.NodeType.BUTTON;
1806
+ nodeType = import_constants3.NodeType.BUTTON;
1800
1807
  break;
1801
1808
  case "SEARCHINPUT":
1802
1809
  case "INPUT":
1803
- nodeType = import_constants2.NodeType.FORM_ITEM;
1810
+ nodeType = import_constants3.NodeType.FORM_ITEM;
1804
1811
  break;
1805
1812
  case "NAV":
1806
1813
  case "LIST":
1807
1814
  case "CELL":
1808
- nodeType = import_constants2.NodeType.CONTAINER;
1815
+ nodeType = import_constants3.NodeType.CONTAINER;
1809
1816
  break;
1810
1817
  default:
1811
1818
  if (attributes.id === "android:id/input" || attributes.id === "android:id/inputArea") {
1812
- nodeType = import_constants2.NodeType.FORM_ITEM;
1819
+ nodeType = import_constants3.NodeType.FORM_ITEM;
1813
1820
  } else {
1814
- nodeType = import_constants2.NodeType.CONTAINER;
1821
+ nodeType = import_constants3.NodeType.CONTAINER;
1815
1822
  }
1816
1823
  break;
1817
1824
  }
1818
1825
  const xpath = getXPathForElement(node);
1819
1826
  const elementInfo = {
1820
1827
  id: nodeHashId,
1821
- indexId: generateId(nodeIndex++),
1828
+ indexId: nodeIndex++,
1822
1829
  nodeHashId,
1823
1830
  locator: xpath,
1824
1831
  attributes: __spreadValues({
@@ -1833,7 +1840,7 @@ function extractTextWithPosition2(initNode) {
1833
1840
  nodeType,
1834
1841
  nodePath: ""
1835
1842
  };
1836
- if (elementInfo.nodeType !== import_constants2.NodeType.CONTAINER) {
1843
+ if (elementInfo.nodeType !== import_constants3.NodeType.CONTAINER) {
1837
1844
  elementInfoArray.push(elementInfo);
1838
1845
  }
1839
1846
  }
@@ -1866,7 +1873,7 @@ var Page = class {
1866
1873
  const { width, height } = await this.browser.getWindowSize();
1867
1874
  const path2 = (0, import_utils7.getTmpFile)("png");
1868
1875
  const screenshotBuffer = await this.browser.saveScreenshot(path2);
1869
- const resizedScreenshotBuffer = await (0, import_img3.resizeImg)(screenshotBuffer, {
1876
+ const resizedScreenshotBuffer = await (0, import_img4.resizeImg)(screenshotBuffer, {
1870
1877
  width,
1871
1878
  height
1872
1879
  });
package/dist/lib/debug.js CHANGED
@@ -128,20 +128,7 @@ function writeFileSyncWithDir(filePath, content, options = {}) {
128
128
  }
129
129
  async function getElementInfos(page) {
130
130
  const captureElementSnapshot = await page.getElementInfos();
131
- const elementsPositionInfo = captureElementSnapshot.map(
132
- (elementInfo, index) => {
133
- var _a;
134
- return {
135
- label: ((_a = elementInfo.indexId) == null ? void 0 : _a.toString()) || index.toString(),
136
- x: elementInfo.rect.left,
137
- y: elementInfo.rect.top,
138
- width: elementInfo.rect.width,
139
- height: elementInfo.rect.height,
140
- attributes: elementInfo.attributes
141
- };
142
- }
143
- );
144
- const elementsPositionInfoWithoutText = elementsPositionInfo.filter(
131
+ const elementsPositionInfoWithoutText = captureElementSnapshot.filter(
145
132
  (elementInfo) => {
146
133
  if (elementInfo.attributes.nodeType === import_constants.NodeType.TEXT) {
147
134
  return false;
@@ -150,7 +137,7 @@ async function getElementInfos(page) {
150
137
  }
151
138
  );
152
139
  return {
153
- elementsPositionInfo,
140
+ elementsPositionInfo: captureElementSnapshot,
154
141
  captureElementSnapshot,
155
142
  elementsPositionInfoWithoutText
156
143
  };
package/dist/lib/index.js CHANGED
@@ -883,7 +883,7 @@ var import_utils5 = require("@midscene/core/utils");
883
883
  var import_node_assert2 = __toESM(require("assert"));
884
884
  var import_core = __toESM(require("@midscene/core"));
885
885
  var import_utils3 = require("@midscene/core/utils");
886
- var import_img2 = require("@midscene/shared/img");
886
+ var import_img3 = require("@midscene/shared/img");
887
887
 
888
888
  // src/common/task-cache.ts
889
889
  var import_node_fs2 = require("fs");
@@ -896,8 +896,10 @@ var import_node_assert = __toESM(require("assert"));
896
896
  var import_node_crypto = require("crypto");
897
897
  var import_node_fs = require("fs");
898
898
  var import_node_path = __toESM(require("path"));
899
+ var import_constants = require("@midscene/shared/constants");
899
900
  var import_fs = require("@midscene/shared/fs");
900
901
  var import_img = require("@midscene/shared/img");
902
+ var import_img2 = require("@midscene/shared/img");
901
903
  var import_dayjs = __toESM(require_dayjs_min());
902
904
 
903
905
  // src/web-element.ts
@@ -908,7 +910,8 @@ var WebElementInfo = class {
908
910
  page,
909
911
  locator,
910
912
  id,
911
- attributes
913
+ attributes,
914
+ indexId
912
915
  }) {
913
916
  this.content = content;
914
917
  this.rect = rect;
@@ -920,6 +923,7 @@ var WebElementInfo = class {
920
923
  this.locator = locator;
921
924
  this.id = id;
922
925
  this.attributes = attributes;
926
+ this.indexId = indexId;
923
927
  }
924
928
  };
925
929
 
@@ -928,19 +932,24 @@ async function parseContextFromWebPage(page, _opt) {
928
932
  (0, import_node_assert.default)(page, "page is required");
929
933
  const url = page.url();
930
934
  const file = await page.screenshot();
931
- const screenshotBuffer = (0, import_node_fs.readFileSync)(file);
932
935
  const screenshotBase64 = (0, import_img.base64Encoded)(file);
933
936
  const captureElementSnapshot = await page.getElementInfos();
934
- const elementsInfo = await alignElements(
935
- screenshotBuffer,
936
- captureElementSnapshot,
937
- page
938
- );
937
+ const elementsInfo = await alignElements(captureElementSnapshot, page);
938
+ const elementsPositionInfoWithoutText = elementsInfo.filter((elementInfo) => {
939
+ if (elementInfo.attributes.nodeType === import_constants.NodeType.TEXT) {
940
+ return false;
941
+ }
942
+ return true;
943
+ });
939
944
  const size = await (0, import_img.imageInfoOfBase64)(screenshotBase64);
945
+ const screenshotBase64WithElementInfos = await (0, import_img2.compositeElementInfoImg)({
946
+ inputImgBase64: screenshotBase64.split(";base64,").pop(),
947
+ elementsPositionInfo: elementsPositionInfoWithoutText
948
+ });
940
949
  return {
941
950
  content: elementsInfo,
942
951
  size,
943
- screenshotBase64,
952
+ screenshotBase64: `data:image/png;base64,${screenshotBase64WithElementInfos}`,
944
953
  url
945
954
  };
946
955
  }
@@ -952,13 +961,13 @@ async function getExtraReturnLogic() {
952
961
  return `${elementInfosScriptContent}midscene_element_inspector.webExtractTextWithPosition()`;
953
962
  }
954
963
  var sizeThreshold = 3;
955
- async function alignElements(screenshotBuffer, elements, page) {
964
+ async function alignElements(elements, page) {
956
965
  const validElements = elements.filter((item) => {
957
966
  return item.rect.height >= sizeThreshold && item.rect.width >= sizeThreshold;
958
967
  });
959
968
  const textsAligned = [];
960
969
  for (const item of validElements) {
961
- const { rect, id, content, attributes, locator } = item;
970
+ const { rect, id, content, attributes, locator, indexId } = item;
962
971
  textsAligned.push(
963
972
  new WebElementInfo({
964
973
  rect,
@@ -966,7 +975,8 @@ async function alignElements(screenshotBuffer, elements, page) {
966
975
  id,
967
976
  content,
968
977
  attributes,
969
- page
978
+ page,
979
+ indexId
970
980
  })
971
981
  );
972
982
  }
@@ -1151,7 +1161,7 @@ var PageTaskExecutor = class {
1151
1161
  const item = {
1152
1162
  type: "screenshot",
1153
1163
  ts: Date.now(),
1154
- screenshot: (0, import_img2.base64Encoded)(file),
1164
+ screenshot: (0, import_img3.base64Encoded)(file),
1155
1165
  timing
1156
1166
  };
1157
1167
  return item;
@@ -1520,13 +1530,13 @@ var PageTaskExecutor = class {
1520
1530
  const assertTask = await this.convertPlanToExecutable([assertPlan]);
1521
1531
  await taskExecutor.append(this.wrapExecutorWithScreenshot(assertTask[0]));
1522
1532
  const output = await taskExecutor.flush();
1523
- if (output.pass) {
1533
+ if (output == null ? void 0 : output.pass) {
1524
1534
  return {
1525
1535
  output: void 0,
1526
1536
  executor: taskExecutor
1527
1537
  };
1528
1538
  }
1529
- errorThought = output.thought;
1539
+ errorThought = (output == null ? void 0 : output.thought) || "unknown error";
1530
1540
  const now = Date.now();
1531
1541
  if (now - startTime < checkIntervalMs) {
1532
1542
  const timeRemaining = checkIntervalMs - (now - startTime);
@@ -1797,7 +1807,7 @@ function waitForNetworkIdle(page) {
1797
1807
  // src/puppeteer/base-page.ts
1798
1808
  var import_node_fs3 = require("fs");
1799
1809
  var import_utils7 = require("@midscene/core/utils");
1800
- var import_img3 = require("@midscene/shared/img");
1810
+ var import_img4 = require("@midscene/shared/img");
1801
1811
  var Page = class {
1802
1812
  evaluate(pageFunction, arg) {
1803
1813
  if (this.pageType === "puppeteer") {
@@ -1822,14 +1832,14 @@ var Page = class {
1822
1832
  deviceScaleFactor: window.devicePixelRatio
1823
1833
  };
1824
1834
  });
1825
- const path3 = (0, import_utils7.getTmpFile)("jpeg");
1835
+ const path3 = (0, import_utils7.getTmpFile)("png");
1826
1836
  await this.page.screenshot({
1827
1837
  path: path3,
1828
1838
  type: "png"
1829
1839
  });
1830
1840
  let buf;
1831
1841
  if (viewportSize.deviceScaleFactor > 1) {
1832
- buf = await (0, import_img3.resizeImg)((0, import_node_fs3.readFileSync)(path3), {
1842
+ buf = await (0, import_img4.resizeImg)((0, import_node_fs3.readFileSync)(path3), {
1833
1843
  width: viewportSize.width,
1834
1844
  height: viewportSize.height
1835
1845
  });
@@ -1921,11 +1931,11 @@ var PuppeteerAgent = class extends PageAgent {
1921
1931
  // src/appium/page.ts
1922
1932
  var import_node_fs4 = __toESM(require("fs"));
1923
1933
  var import_utils9 = require("@midscene/core/utils");
1924
- var import_img4 = require("@midscene/shared/img");
1934
+ var import_img5 = require("@midscene/shared/img");
1925
1935
  var import_xmldom = require("@xmldom/xmldom");
1926
1936
 
1927
1937
  // src/extractor/web-extractor.ts
1928
- var import_constants = require("@midscene/shared/constants");
1938
+ var import_constants2 = require("@midscene/shared/constants");
1929
1939
 
1930
1940
  // src/extractor/util.ts
1931
1941
  var import_js_sha256 = __toESM(require_sha256());
@@ -1942,12 +1952,9 @@ function midsceneGenerateHash(content, rect) {
1942
1952
  const hashHex = (0, import_js_sha256.default)(combined);
1943
1953
  return hashHex.slice(0, 10);
1944
1954
  }
1945
- function generateId(numberId) {
1946
- return `${numberId}`;
1947
- }
1948
1955
 
1949
1956
  // src/extractor/constants.ts
1950
- var import_constants2 = require("@midscene/shared/constants");
1957
+ var import_constants3 = require("@midscene/shared/constants");
1951
1958
 
1952
1959
  // src/extractor/client-extractor.ts
1953
1960
  function getNodeAttributes2(node) {
@@ -2056,35 +2063,35 @@ function extractTextWithPosition2(initNode) {
2056
2063
  let nodeType;
2057
2064
  switch (node.nodeName.toUpperCase()) {
2058
2065
  case "TEXT":
2059
- nodeType = import_constants2.NodeType.TEXT;
2066
+ nodeType = import_constants3.NodeType.TEXT;
2060
2067
  break;
2061
2068
  case "IMAGE":
2062
- nodeType = import_constants2.NodeType.IMG;
2069
+ nodeType = import_constants3.NodeType.IMG;
2063
2070
  break;
2064
2071
  case "BUTTON":
2065
- nodeType = import_constants2.NodeType.BUTTON;
2072
+ nodeType = import_constants3.NodeType.BUTTON;
2066
2073
  break;
2067
2074
  case "SEARCHINPUT":
2068
2075
  case "INPUT":
2069
- nodeType = import_constants2.NodeType.FORM_ITEM;
2076
+ nodeType = import_constants3.NodeType.FORM_ITEM;
2070
2077
  break;
2071
2078
  case "NAV":
2072
2079
  case "LIST":
2073
2080
  case "CELL":
2074
- nodeType = import_constants2.NodeType.CONTAINER;
2081
+ nodeType = import_constants3.NodeType.CONTAINER;
2075
2082
  break;
2076
2083
  default:
2077
2084
  if (attributes.id === "android:id/input" || attributes.id === "android:id/inputArea") {
2078
- nodeType = import_constants2.NodeType.FORM_ITEM;
2085
+ nodeType = import_constants3.NodeType.FORM_ITEM;
2079
2086
  } else {
2080
- nodeType = import_constants2.NodeType.CONTAINER;
2087
+ nodeType = import_constants3.NodeType.CONTAINER;
2081
2088
  }
2082
2089
  break;
2083
2090
  }
2084
2091
  const xpath = getXPathForElement(node);
2085
2092
  const elementInfo = {
2086
2093
  id: nodeHashId,
2087
- indexId: generateId(nodeIndex++),
2094
+ indexId: nodeIndex++,
2088
2095
  nodeHashId,
2089
2096
  locator: xpath,
2090
2097
  attributes: __spreadValues({
@@ -2099,7 +2106,7 @@ function extractTextWithPosition2(initNode) {
2099
2106
  nodeType,
2100
2107
  nodePath: ""
2101
2108
  };
2102
- if (elementInfo.nodeType !== import_constants2.NodeType.CONTAINER) {
2109
+ if (elementInfo.nodeType !== import_constants3.NodeType.CONTAINER) {
2103
2110
  elementInfoArray.push(elementInfo);
2104
2111
  }
2105
2112
  }
@@ -2132,7 +2139,7 @@ var Page2 = class {
2132
2139
  const { width, height } = await this.browser.getWindowSize();
2133
2140
  const path3 = (0, import_utils9.getTmpFile)("png");
2134
2141
  const screenshotBuffer = await this.browser.saveScreenshot(path3);
2135
- const resizedScreenshotBuffer = await (0, import_img4.resizeImg)(screenshotBuffer, {
2142
+ const resizedScreenshotBuffer = await (0, import_img5.resizeImg)(screenshotBuffer, {
2136
2143
  width,
2137
2144
  height
2138
2145
  });
@@ -2290,7 +2297,7 @@ var Page2 = class {
2290
2297
  // src/debug/index.ts
2291
2298
  var import_node_fs5 = require("fs");
2292
2299
  var import_node_path3 = __toESM(require("path"));
2293
- var import_img5 = require("@midscene/shared/img");
2300
+ var import_img6 = require("@midscene/shared/img");
2294
2301
  async function generateExtractData(page, targetDir, saveImgType) {
2295
2302
  const file = await page.screenshot();
2296
2303
  const screenshotBuffer = (0, import_node_fs5.readFileSync)(file);
@@ -2311,12 +2318,12 @@ async function generateExtractData(page, targetDir, saveImgType) {
2311
2318
  const {
2312
2319
  compositeElementInfoImgBase64,
2313
2320
  compositeElementInfoImgWithoutTextBase64
2314
- } = await (0, import_img5.processImageElementInfo)({
2321
+ } = await (0, import_img6.processImageElementInfo)({
2315
2322
  elementsPositionInfo,
2316
2323
  elementsPositionInfoWithoutText,
2317
2324
  inputImgBase64
2318
2325
  });
2319
- const resizeImgBase64 = await (0, import_img5.resizeImg)(inputImgBase64);
2326
+ const resizeImgBase64 = await (0, import_img6.resizeImg)(inputImgBase64);
2320
2327
  const existingSnapshot = (0, import_node_fs5.existsSync)(snapshotJsonPath) ? JSON.parse((0, import_node_fs5.readFileSync)(snapshotJsonPath, "utf-8")) : null;
2321
2328
  if (existingSnapshot && JSON.stringify(existingSnapshot) === JSON.stringify(captureElementSnapshot)) {
2322
2329
  console.log("skip save snapshot for ", targetDir);
@@ -2329,25 +2336,25 @@ async function generateExtractData(page, targetDir, saveImgType) {
2329
2336
  );
2330
2337
  }
2331
2338
  if (!(saveImgType == null ? void 0 : saveImgType.disableInputImage)) {
2332
- await (0, import_img5.saveBase64Image)({
2339
+ await (0, import_img6.saveBase64Image)({
2333
2340
  base64Data: inputImgBase64,
2334
2341
  outputPath: inputImagePath
2335
2342
  });
2336
2343
  }
2337
2344
  if (!(saveImgType == null ? void 0 : saveImgType.disableOutputImage)) {
2338
- await (0, import_img5.saveBase64Image)({
2345
+ await (0, import_img6.saveBase64Image)({
2339
2346
  base64Data: compositeElementInfoImgBase64,
2340
2347
  outputPath: outputImagePath
2341
2348
  });
2342
2349
  }
2343
2350
  if (!(saveImgType == null ? void 0 : saveImgType.disableOutputWithoutTextImg)) {
2344
- await (0, import_img5.saveBase64Image)({
2351
+ await (0, import_img6.saveBase64Image)({
2345
2352
  base64Data: compositeElementInfoImgWithoutTextBase64,
2346
2353
  outputPath: outputWithoutTextImgPath
2347
2354
  });
2348
2355
  }
2349
2356
  if (!(saveImgType == null ? void 0 : saveImgType.disableResizeOutputImg)) {
2350
- await (0, import_img5.saveBase64Image)({
2357
+ await (0, import_img6.saveBase64Image)({
2351
2358
  base64Data: resizeImgBase64,
2352
2359
  outputPath: resizeOutputImgPath
2353
2360
  });
@@ -2367,29 +2374,16 @@ function writeFileSyncWithDir(filePath, content, options = {}) {
2367
2374
  }
2368
2375
  async function getElementInfos(page) {
2369
2376
  const captureElementSnapshot = await page.getElementInfos();
2370
- const elementsPositionInfo = captureElementSnapshot.map(
2371
- (elementInfo, index) => {
2372
- var _a;
2373
- return {
2374
- label: ((_a = elementInfo.indexId) == null ? void 0 : _a.toString()) || index.toString(),
2375
- x: elementInfo.rect.left,
2376
- y: elementInfo.rect.top,
2377
- width: elementInfo.rect.width,
2378
- height: elementInfo.rect.height,
2379
- attributes: elementInfo.attributes
2380
- };
2381
- }
2382
- );
2383
- const elementsPositionInfoWithoutText = elementsPositionInfo.filter(
2377
+ const elementsPositionInfoWithoutText = captureElementSnapshot.filter(
2384
2378
  (elementInfo) => {
2385
- if (elementInfo.attributes.nodeType === import_constants2.NodeType.TEXT) {
2379
+ if (elementInfo.attributes.nodeType === import_constants3.NodeType.TEXT) {
2386
2380
  return false;
2387
2381
  }
2388
2382
  return true;
2389
2383
  }
2390
2384
  );
2391
2385
  return {
2392
- elementsPositionInfo,
2386
+ elementsPositionInfo: captureElementSnapshot,
2393
2387
  captureElementSnapshot,
2394
2388
  elementsPositionInfoWithoutText
2395
2389
  };
@@ -337,8 +337,10 @@ var import_node_assert = __toESM(require("assert"));
337
337
  var import_node_crypto = require("crypto");
338
338
  var import_node_fs = require("fs");
339
339
  var import_node_path = __toESM(require("path"));
340
+ var import_constants = require("@midscene/shared/constants");
340
341
  var import_fs = require("@midscene/shared/fs");
341
342
  var import_img = require("@midscene/shared/img");
343
+ var import_img2 = require("@midscene/shared/img");
342
344
  var import_dayjs = __toESM(require_dayjs_min());
343
345
  function reportFileName(tag = "web") {
344
346
  const dateTimeInFileName = (0, import_dayjs.default)().format("YYYY-MM-DD_HH-mm-ss-SSS");