@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
@@ -497,6 +497,23 @@ function scrollParamStr(scrollParam) {
497
497
  }
498
498
  return `${scrollParam.direction || "down"}, ${scrollParam.scrollType || "once"}, ${scrollParam.distance || "distance-not-set"}`;
499
499
  }
500
+ function pullParamStr(pullParam) {
501
+ if (!pullParam) {
502
+ return "";
503
+ }
504
+ const parts = [];
505
+ parts.push(`direction: ${pullParam.direction || "down"}`);
506
+ if (pullParam.startPoint) {
507
+ parts.push(`start: (${pullParam.startPoint.x}, ${pullParam.startPoint.y})`);
508
+ }
509
+ if (pullParam.distance) {
510
+ parts.push(`distance: ${pullParam.distance}`);
511
+ }
512
+ if (pullParam.duration) {
513
+ parts.push(`duration: ${pullParam.duration}ms`);
514
+ }
515
+ return parts.join(", ");
516
+ }
500
517
  function taskTitleStr(type, prompt) {
501
518
  if (prompt) {
502
519
  return `${type} - ${prompt}`;
@@ -519,6 +536,8 @@ function paramStr(task) {
519
536
  value = `${task?.param?.timeMs}ms`;
520
537
  } else if (typeof task?.param?.scrollType === "string") {
521
538
  value = scrollParamStr(task?.param);
539
+ } else if (typeof task?.param?.direction === "string" && task?.subType === "AndroidPull") {
540
+ value = pullParamStr(task?.param);
522
541
  } else if (typeof task?.param?.value !== "undefined") {
523
542
  value = task?.param?.value;
524
543
  }
@@ -582,7 +601,7 @@ var import_js_yaml3 = __toESM(require("js-yaml"));
582
601
  var import_semver = __toESM(require("semver"));
583
602
 
584
603
  // package.json
585
- var version = "0.24.1";
604
+ var version = "0.24.2-beta-20250730123854.0";
586
605
 
587
606
  // src/common/task-cache.ts
588
607
  var DEFAULT_CACHE_MAX_FILENAME_LENGTH = 200;
@@ -726,7 +745,18 @@ cache file: ${cacheFile}`
726
745
  (0, import_node_fs2.mkdirSync)(dir, { recursive: true });
727
746
  debug("created cache directory: %s", dir);
728
747
  }
729
- const yamlData = import_js_yaml3.default.dump(this.cache);
748
+ const sortedCaches = [...this.cache.caches].sort((a, b) => {
749
+ if (a.type === "plan" && b.type === "locate")
750
+ return -1;
751
+ if (a.type === "locate" && b.type === "plan")
752
+ return 1;
753
+ return 0;
754
+ });
755
+ const cacheToWrite = {
756
+ ...this.cache,
757
+ caches: sortedCaches
758
+ };
759
+ const yamlData = import_js_yaml3.default.dump(cacheToWrite);
730
760
  (0, import_node_fs2.writeFileSync)(this.cacheFilePath, yamlData);
731
761
  debug("cache flushed to file: %s", this.cacheFilePath);
732
762
  } catch (err) {
@@ -943,6 +973,16 @@ var PageTaskExecutor = class {
943
973
  }
944
974
  async getElementXpath(pageContext, element) {
945
975
  let elementId = element?.id;
976
+ if (element?.isOrderSensitive !== void 0) {
977
+ const xpaths = await this.page.getXpathsByPoint(
978
+ {
979
+ left: element.center[0],
980
+ top: element.center[1]
981
+ },
982
+ element?.isOrderSensitive
983
+ );
984
+ return xpaths;
985
+ }
946
986
  if (element?.attributes?.nodeType === import_constants.NodeType.POSITION) {
947
987
  await this.insight.contextRetrieverFn("locate");
948
988
  const info = (0, import_ai_model2.elementByPositionWithElementInfo)(
@@ -1437,6 +1477,51 @@ var PageTaskExecutor = class {
1437
1477
  }
1438
1478
  };
1439
1479
  tasks.push(taskActionAndroidRecentAppsButton);
1480
+ } else if (plan2.type === "AndroidLongPress") {
1481
+ const taskActionAndroidLongPress = {
1482
+ type: "Action",
1483
+ subType: "AndroidLongPress",
1484
+ param: plan2.param,
1485
+ thought: plan2.thought,
1486
+ locate: plan2.locate,
1487
+ executor: async (param) => {
1488
+ (0, import_utils9.assert)(
1489
+ isAndroidPage(this.page),
1490
+ "Cannot use long press on non-Android devices"
1491
+ );
1492
+ const { x, y, duration } = param;
1493
+ await this.page.longPress(x, y, duration);
1494
+ }
1495
+ };
1496
+ tasks.push(taskActionAndroidLongPress);
1497
+ } else if (plan2.type === "AndroidPull") {
1498
+ const taskActionAndroidPull = {
1499
+ type: "Action",
1500
+ subType: "AndroidPull",
1501
+ param: plan2.param,
1502
+ thought: plan2.thought,
1503
+ locate: plan2.locate,
1504
+ executor: async (param) => {
1505
+ (0, import_utils9.assert)(
1506
+ isAndroidPage(this.page),
1507
+ "Cannot use pull action on non-Android devices"
1508
+ );
1509
+ const { direction, startPoint, distance, duration } = param;
1510
+ const convertedStartPoint = startPoint ? { left: startPoint.x, top: startPoint.y } : void 0;
1511
+ if (direction === "down") {
1512
+ await this.page.pullDown(
1513
+ convertedStartPoint,
1514
+ distance,
1515
+ duration
1516
+ );
1517
+ } else if (direction === "up") {
1518
+ await this.page.pullUp(convertedStartPoint, distance, duration);
1519
+ } else {
1520
+ throw new Error(`Unknown pull direction: ${direction}`);
1521
+ }
1522
+ }
1523
+ };
1524
+ tasks.push(taskActionAndroidPull);
1440
1525
  } else {
1441
1526
  throw new Error(`Unknown or unsupported task type: ${plan2.type}`);
1442
1527
  }
@@ -2651,6 +2736,12 @@ var Page = class {
2651
2736
  `${elementInfosScriptContent}midscene_element_inspector.getXpathsById('${id}')`
2652
2737
  );
2653
2738
  }
2739
+ async getXpathsByPoint(point, isOrderSensitive) {
2740
+ const elementInfosScriptContent = (0, import_fs.getElementInfosScriptContent)();
2741
+ return this.evaluateJavaScript(
2742
+ `${elementInfosScriptContent}midscene_element_inspector.getXpathsByPoint({left: ${point.left}, top: ${point.top}}, ${isOrderSensitive})`
2743
+ );
2744
+ }
2654
2745
  async getElementInfoByXpath(xpath) {
2655
2746
  const elementInfosScriptContent = (0, import_fs.getElementInfosScriptContent)();
2656
2747
  return this.evaluateJavaScript(