@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
@@ -490,6 +490,23 @@ function scrollParamStr(scrollParam) {
490
490
  }
491
491
  return `${scrollParam.direction || "down"}, ${scrollParam.scrollType || "once"}, ${scrollParam.distance || "distance-not-set"}`;
492
492
  }
493
+ function pullParamStr(pullParam) {
494
+ if (!pullParam) {
495
+ return "";
496
+ }
497
+ const parts = [];
498
+ parts.push(`direction: ${pullParam.direction || "down"}`);
499
+ if (pullParam.startPoint) {
500
+ parts.push(`start: (${pullParam.startPoint.x}, ${pullParam.startPoint.y})`);
501
+ }
502
+ if (pullParam.distance) {
503
+ parts.push(`distance: ${pullParam.distance}`);
504
+ }
505
+ if (pullParam.duration) {
506
+ parts.push(`duration: ${pullParam.duration}ms`);
507
+ }
508
+ return parts.join(", ");
509
+ }
493
510
  function taskTitleStr(type, prompt) {
494
511
  if (prompt) {
495
512
  return `${type} - ${prompt}`;
@@ -512,6 +529,8 @@ function paramStr(task) {
512
529
  value = `${task?.param?.timeMs}ms`;
513
530
  } else if (typeof task?.param?.scrollType === "string") {
514
531
  value = scrollParamStr(task?.param);
532
+ } else if (typeof task?.param?.direction === "string" && task?.subType === "AndroidPull") {
533
+ value = pullParamStr(task?.param);
515
534
  } else if (typeof task?.param?.value !== "undefined") {
516
535
  value = task?.param?.value;
517
536
  }
@@ -575,7 +594,7 @@ var import_js_yaml3 = __toESM(require("js-yaml"));
575
594
  var import_semver = __toESM(require("semver"));
576
595
 
577
596
  // package.json
578
- var version = "0.24.1";
597
+ var version = "0.24.2-beta-20250730123854.0";
579
598
 
580
599
  // src/common/task-cache.ts
581
600
  var DEFAULT_CACHE_MAX_FILENAME_LENGTH = 200;
@@ -719,7 +738,18 @@ cache file: ${cacheFile}`
719
738
  (0, import_node_fs2.mkdirSync)(dir, { recursive: true });
720
739
  debug("created cache directory: %s", dir);
721
740
  }
722
- const yamlData = import_js_yaml3.default.dump(this.cache);
741
+ const sortedCaches = [...this.cache.caches].sort((a, b) => {
742
+ if (a.type === "plan" && b.type === "locate")
743
+ return -1;
744
+ if (a.type === "locate" && b.type === "plan")
745
+ return 1;
746
+ return 0;
747
+ });
748
+ const cacheToWrite = {
749
+ ...this.cache,
750
+ caches: sortedCaches
751
+ };
752
+ const yamlData = import_js_yaml3.default.dump(cacheToWrite);
723
753
  (0, import_node_fs2.writeFileSync)(this.cacheFilePath, yamlData);
724
754
  debug("cache flushed to file: %s", this.cacheFilePath);
725
755
  } catch (err) {
@@ -936,6 +966,16 @@ var PageTaskExecutor = class {
936
966
  }
937
967
  async getElementXpath(pageContext, element) {
938
968
  let elementId = element?.id;
969
+ if (element?.isOrderSensitive !== void 0) {
970
+ const xpaths = await this.page.getXpathsByPoint(
971
+ {
972
+ left: element.center[0],
973
+ top: element.center[1]
974
+ },
975
+ element?.isOrderSensitive
976
+ );
977
+ return xpaths;
978
+ }
939
979
  if (element?.attributes?.nodeType === import_constants.NodeType.POSITION) {
940
980
  await this.insight.contextRetrieverFn("locate");
941
981
  const info = (0, import_ai_model2.elementByPositionWithElementInfo)(
@@ -1430,6 +1470,51 @@ var PageTaskExecutor = class {
1430
1470
  }
1431
1471
  };
1432
1472
  tasks.push(taskActionAndroidRecentAppsButton);
1473
+ } else if (plan2.type === "AndroidLongPress") {
1474
+ const taskActionAndroidLongPress = {
1475
+ type: "Action",
1476
+ subType: "AndroidLongPress",
1477
+ param: plan2.param,
1478
+ thought: plan2.thought,
1479
+ locate: plan2.locate,
1480
+ executor: async (param) => {
1481
+ (0, import_utils9.assert)(
1482
+ isAndroidPage(this.page),
1483
+ "Cannot use long press on non-Android devices"
1484
+ );
1485
+ const { x, y, duration } = param;
1486
+ await this.page.longPress(x, y, duration);
1487
+ }
1488
+ };
1489
+ tasks.push(taskActionAndroidLongPress);
1490
+ } else if (plan2.type === "AndroidPull") {
1491
+ const taskActionAndroidPull = {
1492
+ type: "Action",
1493
+ subType: "AndroidPull",
1494
+ param: plan2.param,
1495
+ thought: plan2.thought,
1496
+ locate: plan2.locate,
1497
+ executor: async (param) => {
1498
+ (0, import_utils9.assert)(
1499
+ isAndroidPage(this.page),
1500
+ "Cannot use pull action on non-Android devices"
1501
+ );
1502
+ const { direction, startPoint, distance, duration } = param;
1503
+ const convertedStartPoint = startPoint ? { left: startPoint.x, top: startPoint.y } : void 0;
1504
+ if (direction === "down") {
1505
+ await this.page.pullDown(
1506
+ convertedStartPoint,
1507
+ distance,
1508
+ duration
1509
+ );
1510
+ } else if (direction === "up") {
1511
+ await this.page.pullUp(convertedStartPoint, distance, duration);
1512
+ } else {
1513
+ throw new Error(`Unknown pull direction: ${direction}`);
1514
+ }
1515
+ }
1516
+ };
1517
+ tasks.push(taskActionAndroidPull);
1433
1518
  } else {
1434
1519
  throw new Error(`Unknown or unsupported task type: ${plan2.type}`);
1435
1520
  }
@@ -2644,6 +2729,12 @@ var Page = class {
2644
2729
  `${elementInfosScriptContent}midscene_element_inspector.getXpathsById('${id}')`
2645
2730
  );
2646
2731
  }
2732
+ async getXpathsByPoint(point, isOrderSensitive) {
2733
+ const elementInfosScriptContent = (0, import_fs.getElementInfosScriptContent)();
2734
+ return this.evaluateJavaScript(
2735
+ `${elementInfosScriptContent}midscene_element_inspector.getXpathsByPoint({left: ${point.left}, top: ${point.top}}, ${isOrderSensitive})`
2736
+ );
2737
+ }
2647
2738
  async getElementInfoByXpath(xpath) {
2648
2739
  const elementInfosScriptContent = (0, import_fs.getElementInfosScriptContent)();
2649
2740
  return this.evaluateJavaScript(