@midscene/web 0.24.1 → 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.
Files changed (74) hide show
  1. package/dist/es/agent.js +87 -2
  2. package/dist/es/agent.js.map +1 -1
  3. package/dist/es/bridge-mode-browser.js +14 -3
  4. package/dist/es/bridge-mode-browser.js.map +1 -1
  5. package/dist/es/bridge-mode.js +89 -4
  6. package/dist/es/bridge-mode.js.map +1 -1
  7. package/dist/es/chrome-extension.js +99 -3
  8. package/dist/es/chrome-extension.js.map +1 -1
  9. package/dist/es/index.js +93 -2
  10. package/dist/es/index.js.map +1 -1
  11. package/dist/es/midscene-playground.js +90 -2
  12. package/dist/es/midscene-playground.js.map +1 -1
  13. package/dist/es/midscene-server.js.map +1 -1
  14. package/dist/es/playground.js +90 -2
  15. package/dist/es/playground.js.map +1 -1
  16. package/dist/es/playwright-report.js +3 -4
  17. package/dist/es/playwright-report.js.map +1 -1
  18. package/dist/es/playwright-reporter.js +3 -4
  19. package/dist/es/playwright-reporter.js.map +1 -1
  20. package/dist/es/playwright.js +93 -2
  21. package/dist/es/playwright.js.map +1 -1
  22. package/dist/es/puppeteer-agent-launcher.js +93 -2
  23. package/dist/es/puppeteer-agent-launcher.js.map +1 -1
  24. package/dist/es/puppeteer.js +93 -2
  25. package/dist/es/puppeteer.js.map +1 -1
  26. package/dist/es/ui-utils.js +20 -0
  27. package/dist/es/ui-utils.js.map +1 -1
  28. package/dist/es/utils.js.map +1 -1
  29. package/dist/lib/agent.js +87 -2
  30. package/dist/lib/agent.js.map +1 -1
  31. package/dist/lib/bridge-mode-browser.js +14 -3
  32. package/dist/lib/bridge-mode-browser.js.map +1 -1
  33. package/dist/lib/bridge-mode.js +89 -4
  34. package/dist/lib/bridge-mode.js.map +1 -1
  35. package/dist/lib/chrome-extension.js +99 -3
  36. package/dist/lib/chrome-extension.js.map +1 -1
  37. package/dist/lib/index.js +93 -2
  38. package/dist/lib/index.js.map +1 -1
  39. package/dist/lib/midscene-playground.js +90 -2
  40. package/dist/lib/midscene-playground.js.map +1 -1
  41. package/dist/lib/midscene-server.js.map +1 -1
  42. package/dist/lib/playground.js +90 -2
  43. package/dist/lib/playground.js.map +1 -1
  44. package/dist/lib/playwright-report.js +3 -4
  45. package/dist/lib/playwright-report.js.map +1 -1
  46. package/dist/lib/playwright-reporter.js +3 -4
  47. package/dist/lib/playwright-reporter.js.map +1 -1
  48. package/dist/lib/playwright.js +93 -2
  49. package/dist/lib/playwright.js.map +1 -1
  50. package/dist/lib/puppeteer-agent-launcher.js +93 -2
  51. package/dist/lib/puppeteer-agent-launcher.js.map +1 -1
  52. package/dist/lib/puppeteer.js +93 -2
  53. package/dist/lib/puppeteer.js.map +1 -1
  54. package/dist/lib/ui-utils.js +21 -0
  55. package/dist/lib/ui-utils.js.map +1 -1
  56. package/dist/lib/utils.js.map +1 -1
  57. package/dist/types/agent.d.ts +1 -1
  58. package/dist/types/bridge-mode-browser.d.ts +2 -2
  59. package/dist/types/bridge-mode.d.ts +2 -2
  60. package/dist/types/{browser-a44b28ea.d.ts → browser-e74eab47.d.ts} +1 -1
  61. package/dist/types/chrome-extension.d.ts +2 -2
  62. package/dist/types/index.d.ts +2 -2
  63. package/dist/types/midscene-server.d.ts +1 -1
  64. package/dist/types/{page-b8f0ca7d.d.ts → page-34780923.d.ts} +15 -0
  65. package/dist/types/playground.d.ts +2 -2
  66. package/dist/types/playwright-report.d.ts +5 -1
  67. package/dist/types/playwright.d.ts +1 -1
  68. package/dist/types/puppeteer-agent-launcher.d.ts +1 -1
  69. package/dist/types/puppeteer.d.ts +2 -2
  70. package/dist/types/ui-utils.d.ts +3 -2
  71. package/dist/types/{utils-fcd484e0.d.ts → utils-169da810.d.ts} +1 -1
  72. package/dist/types/utils.d.ts +1 -1
  73. package/dist/types/yaml.d.ts +2 -2
  74. package/package.json +3 -3
@@ -75,7 +75,7 @@ import yaml from "js-yaml";
75
75
  import semver from "semver";
76
76
 
77
77
  // package.json
78
- var version = "0.24.1";
78
+ var version = "0.24.2-beta-20250730123854.0";
79
79
 
80
80
  // src/common/task-cache.ts
81
81
  var DEFAULT_CACHE_MAX_FILENAME_LENGTH = 200;
@@ -219,7 +219,18 @@ cache file: ${cacheFile}`
219
219
  mkdirSync(dir, { recursive: true });
220
220
  debug("created cache directory: %s", dir);
221
221
  }
222
- const yamlData = yaml.dump(this.cache);
222
+ const sortedCaches = [...this.cache.caches].sort((a, b) => {
223
+ if (a.type === "plan" && b.type === "locate")
224
+ return -1;
225
+ if (a.type === "locate" && b.type === "plan")
226
+ return 1;
227
+ return 0;
228
+ });
229
+ const cacheToWrite = {
230
+ ...this.cache,
231
+ caches: sortedCaches
232
+ };
233
+ const yamlData = yaml.dump(cacheToWrite);
223
234
  writeFileSync(this.cacheFilePath, yamlData);
224
235
  debug("cache flushed to file: %s", this.cacheFilePath);
225
236
  } catch (err) {
@@ -857,6 +868,23 @@ function scrollParamStr(scrollParam) {
857
868
  }
858
869
  return `${scrollParam.direction || "down"}, ${scrollParam.scrollType || "once"}, ${scrollParam.distance || "distance-not-set"}`;
859
870
  }
871
+ function pullParamStr(pullParam) {
872
+ if (!pullParam) {
873
+ return "";
874
+ }
875
+ const parts = [];
876
+ parts.push(`direction: ${pullParam.direction || "down"}`);
877
+ if (pullParam.startPoint) {
878
+ parts.push(`start: (${pullParam.startPoint.x}, ${pullParam.startPoint.y})`);
879
+ }
880
+ if (pullParam.distance) {
881
+ parts.push(`distance: ${pullParam.distance}`);
882
+ }
883
+ if (pullParam.duration) {
884
+ parts.push(`duration: ${pullParam.duration}ms`);
885
+ }
886
+ return parts.join(", ");
887
+ }
860
888
  function taskTitleStr(type, prompt) {
861
889
  if (prompt) {
862
890
  return `${type} - ${prompt}`;
@@ -879,6 +907,8 @@ function paramStr(task) {
879
907
  value = `${task?.param?.timeMs}ms`;
880
908
  } else if (typeof task?.param?.scrollType === "string") {
881
909
  value = scrollParamStr(task?.param);
910
+ } else if (typeof task?.param?.direction === "string" && task?.subType === "AndroidPull") {
911
+ value = pullParamStr(task?.param);
882
912
  } else if (typeof task?.param?.value !== "undefined") {
883
913
  value = task?.param?.value;
884
914
  }
@@ -944,6 +974,16 @@ var PageTaskExecutor = class {
944
974
  }
945
975
  async getElementXpath(pageContext, element) {
946
976
  let elementId = element?.id;
977
+ if (element?.isOrderSensitive !== void 0) {
978
+ const xpaths = await this.page.getXpathsByPoint(
979
+ {
980
+ left: element.center[0],
981
+ top: element.center[1]
982
+ },
983
+ element?.isOrderSensitive
984
+ );
985
+ return xpaths;
986
+ }
947
987
  if (element?.attributes?.nodeType === NodeType.POSITION) {
948
988
  await this.insight.contextRetrieverFn("locate");
949
989
  const info = elementByPositionWithElementInfo2(
@@ -1438,6 +1478,51 @@ var PageTaskExecutor = class {
1438
1478
  }
1439
1479
  };
1440
1480
  tasks.push(taskActionAndroidRecentAppsButton);
1481
+ } else if (plan2.type === "AndroidLongPress") {
1482
+ const taskActionAndroidLongPress = {
1483
+ type: "Action",
1484
+ subType: "AndroidLongPress",
1485
+ param: plan2.param,
1486
+ thought: plan2.thought,
1487
+ locate: plan2.locate,
1488
+ executor: async (param) => {
1489
+ assert5(
1490
+ isAndroidPage(this.page),
1491
+ "Cannot use long press on non-Android devices"
1492
+ );
1493
+ const { x, y, duration } = param;
1494
+ await this.page.longPress(x, y, duration);
1495
+ }
1496
+ };
1497
+ tasks.push(taskActionAndroidLongPress);
1498
+ } else if (plan2.type === "AndroidPull") {
1499
+ const taskActionAndroidPull = {
1500
+ type: "Action",
1501
+ subType: "AndroidPull",
1502
+ param: plan2.param,
1503
+ thought: plan2.thought,
1504
+ locate: plan2.locate,
1505
+ executor: async (param) => {
1506
+ assert5(
1507
+ isAndroidPage(this.page),
1508
+ "Cannot use pull action on non-Android devices"
1509
+ );
1510
+ const { direction, startPoint, distance, duration } = param;
1511
+ const convertedStartPoint = startPoint ? { left: startPoint.x, top: startPoint.y } : void 0;
1512
+ if (direction === "down") {
1513
+ await this.page.pullDown(
1514
+ convertedStartPoint,
1515
+ distance,
1516
+ duration
1517
+ );
1518
+ } else if (direction === "up") {
1519
+ await this.page.pullUp(convertedStartPoint, distance, duration);
1520
+ } else {
1521
+ throw new Error(`Unknown pull direction: ${direction}`);
1522
+ }
1523
+ }
1524
+ };
1525
+ tasks.push(taskActionAndroidPull);
1441
1526
  } else {
1442
1527
  throw new Error(`Unknown or unsupported task type: ${plan2.type}`);
1443
1528
  }
@@ -2794,7 +2879,7 @@ function sleep2(ms) {
2794
2879
  var ChromeExtensionProxyPage = class {
2795
2880
  constructor(forceSameTabNavigation) {
2796
2881
  this.pageType = "chrome-extension-proxy";
2797
- this.version = "0.24.1";
2882
+ this.version = "0.24.2-beta-20250730123854.0";
2798
2883
  this.activeTabId = null;
2799
2884
  this.tabIdOfDebuggerAttached = null;
2800
2885
  this.attachingDebugger = null;
@@ -3141,6 +3226,17 @@ var ChromeExtensionProxyPage = class {
3141
3226
  });
3142
3227
  return result.result.value;
3143
3228
  }
3229
+ async getXpathsByPoint(point, isOrderSensitive) {
3230
+ const script = await getHtmlElementScript();
3231
+ await this.sendCommandToDebugger("Runtime.evaluate", {
3232
+ expression: script
3233
+ });
3234
+ const result = await this.sendCommandToDebugger("Runtime.evaluate", {
3235
+ expression: `window.midscene_element_inspector.getXpathsByPoint({left: ${point.left}, top: ${point.top}}, ${isOrderSensitive})`,
3236
+ returnByValue: true
3237
+ });
3238
+ return result.result.value;
3239
+ }
3144
3240
  async getElementInfoByXpath(xpath) {
3145
3241
  const script = await getHtmlElementScript();
3146
3242
  await this.sendCommandToDebugger("Runtime.evaluate", {