@midscene/web 0.10.1 → 0.10.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.
Files changed (34) hide show
  1. package/dist/es/appium.js +41 -5
  2. package/dist/es/bridge-mode-browser.js +43 -396
  3. package/dist/es/bridge-mode.js +44 -15
  4. package/dist/es/chrome-extension.js +59 -398
  5. package/dist/es/index.js +96 -9
  6. package/dist/es/midscene-playground.js +26 -5
  7. package/dist/es/playground.js +26 -5
  8. package/dist/es/playwright.js +62 -8
  9. package/dist/es/puppeteer.js +90 -13
  10. package/dist/lib/appium.js +41 -5
  11. package/dist/lib/bridge-mode-browser.js +43 -396
  12. package/dist/lib/bridge-mode.js +44 -15
  13. package/dist/lib/chrome-extension.js +59 -398
  14. package/dist/lib/index.js +96 -9
  15. package/dist/lib/midscene-playground.js +26 -5
  16. package/dist/lib/playground.js +26 -5
  17. package/dist/lib/playwright.js +62 -8
  18. package/dist/lib/puppeteer.js +90 -13
  19. package/dist/types/appium.d.ts +3 -3
  20. package/dist/types/bridge-mode-browser.d.ts +3 -3
  21. package/dist/types/bridge-mode.d.ts +6 -5
  22. package/dist/types/{browser-fd2e9b68.d.ts → browser-bc6c204c.d.ts} +1 -1
  23. package/dist/types/chrome-extension.d.ts +4 -4
  24. package/dist/types/debug.d.ts +2 -2
  25. package/dist/types/index.d.ts +4 -4
  26. package/dist/types/{page-fc3be0ec.d.ts → page-cfd75cdf.d.ts} +34 -4
  27. package/dist/types/playground.d.ts +4 -4
  28. package/dist/types/playwright.d.ts +4 -4
  29. package/dist/types/puppeteer.d.ts +8 -7
  30. package/dist/types/{tasks-f2973dd7.d.ts → tasks-681afd8a.d.ts} +4 -3
  31. package/dist/types/{utils-ccbb6ff6.d.ts → utils-1c43a008.d.ts} +1 -1
  32. package/dist/types/utils.d.ts +2 -2
  33. package/dist/types/yaml.d.ts +4 -4
  34. package/package.json +5 -3
@@ -328,7 +328,8 @@ var require_dayjs_min = __commonJS({
328
328
  // src/bridge-mode/index.ts
329
329
  var bridge_mode_exports = {};
330
330
  __export(bridge_mode_exports, {
331
- AgentOverChromeBridge: () => AgentOverChromeBridge
331
+ AgentOverChromeBridge: () => AgentOverChromeBridge,
332
+ overrideAIConfig: () => import_env4.overrideAIConfig
332
333
  });
333
334
  module.exports = __toCommonJS(bridge_mode_exports);
334
335
 
@@ -555,7 +556,10 @@ var PageTaskExecutor = class {
555
556
  locate: plan2.locate,
556
557
  executor: async (param, taskContext) => {
557
558
  const { task } = taskContext;
558
- (0, import_node_assert.default)((param == null ? void 0 : param.prompt) || (param == null ? void 0 : param.id), "No prompt or id to locate");
559
+ (0, import_node_assert.default)(
560
+ (param == null ? void 0 : param.prompt) || (param == null ? void 0 : param.id) || (param == null ? void 0 : param.position),
561
+ "No prompt or id or position to locate"
562
+ );
559
563
  let insightDump;
560
564
  const dumpCollector = (dump) => {
561
565
  insightDump = dump;
@@ -710,6 +714,22 @@ var PageTaskExecutor = class {
710
714
  }
711
715
  };
712
716
  tasks.push(taskActionTap);
717
+ } else if (plan2.type === "Drag") {
718
+ const taskActionDrag = {
719
+ type: "Action",
720
+ subType: "Drag",
721
+ param: plan2.param,
722
+ thought: plan2.thought,
723
+ locate: plan2.locate,
724
+ executor: async (taskParam) => {
725
+ (0, import_node_assert.default)(
726
+ (taskParam == null ? void 0 : taskParam.start_box) && (taskParam == null ? void 0 : taskParam.end_box),
727
+ "No start_box or end_box to drag"
728
+ );
729
+ await this.page.mouse.drag(taskParam.start_box, taskParam.end_box);
730
+ }
731
+ };
732
+ tasks.push(taskActionDrag);
713
733
  } else if (plan2.type === "Hover") {
714
734
  const taskActionHover = {
715
735
  type: "Action",
@@ -744,9 +764,9 @@ var PageTaskExecutor = class {
744
764
  } else if (scrollToEventName === "untilLeft") {
745
765
  await this.page.scrollUntilLeft(startingPoint);
746
766
  } else if (scrollToEventName === "once" || !scrollToEventName) {
747
- if (taskParam.direction === "down" || !taskParam.direction) {
767
+ if ((taskParam == null ? void 0 : taskParam.direction) === "down" || !taskParam || !taskParam.direction) {
748
768
  await this.page.scrollDown(
749
- taskParam.distance || void 0,
769
+ (taskParam == null ? void 0 : taskParam.distance) || void 0,
750
770
  startingPoint
751
771
  );
752
772
  } else if (taskParam.direction === "up") {
@@ -941,6 +961,7 @@ var PageTaskExecutor = class {
941
961
  userPrompt
942
962
  },
943
963
  executor: async (param, executorContext) => {
964
+ var _a;
944
965
  const shotTime = Date.now();
945
966
  const pageContext = await this.insight.contextRetrieverFn("locate");
946
967
  const recordItem = {
@@ -977,7 +998,7 @@ var PageTaskExecutor = class {
977
998
  return {
978
999
  output: {
979
1000
  actions,
980
- thought: actions[0].thought,
1001
+ thought: (_a = actions[0]) == null ? void 0 : _a.thought,
981
1002
  actionType: actions[0].type,
982
1003
  taskWillBeAccomplished: false,
983
1004
  furtherPlan: {
@@ -1649,7 +1670,7 @@ var BridgeServer = class {
1649
1670
  this.socket = socket;
1650
1671
  const clientVersion = socket.handshake.query.version;
1651
1672
  console.log(
1652
- `Bridge connected, cli-side version v${"0.10.1"}, browser-side version v${clientVersion}`
1673
+ `Bridge connected, cli-side version v${"0.10.2"}, browser-side version v${clientVersion}`
1653
1674
  );
1654
1675
  socket.on("bridge-call-response" /* CallResponse */, (params) => {
1655
1676
  const id = params.id;
@@ -1682,7 +1703,7 @@ var BridgeServer = class {
1682
1703
  var _a;
1683
1704
  (_a = this.onConnect) == null ? void 0 : _a.call(this);
1684
1705
  const payload = {
1685
- version: "0.10.1"
1706
+ version: "0.10.2"
1686
1707
  };
1687
1708
  socket.emit("bridge-connected" /* Connected */, payload);
1688
1709
  Promise.resolve().then(() => {
@@ -1809,7 +1830,8 @@ var getBridgePageInCliSide = () => {
1809
1830
  const mouse = {
1810
1831
  click: bridgeCaller("mouse.click" /* Click */),
1811
1832
  wheel: bridgeCaller("mouse.wheel" /* Wheel */),
1812
- move: bridgeCaller("mouse.move" /* Move */)
1833
+ move: bridgeCaller("mouse.move" /* Move */),
1834
+ drag: bridgeCaller("mouse.drag" /* Drag */)
1813
1835
  };
1814
1836
  return mouse;
1815
1837
  }
@@ -1835,13 +1857,16 @@ var getBridgePageInCliSide = () => {
1835
1857
  });
1836
1858
  };
1837
1859
  var AgentOverChromeBridge = class extends PageAgent {
1838
- constructor() {
1860
+ constructor(opts) {
1839
1861
  const page = getBridgePageInCliSide();
1840
- super(page, {
1841
- onTaskStartTip: (tip) => {
1842
- this.page.showStatusMessage(tip);
1843
- }
1844
- });
1862
+ super(
1863
+ page,
1864
+ Object.assign(opts || {}, {
1865
+ onTaskStartTip: (tip) => {
1866
+ this.page.showStatusMessage(tip);
1867
+ }
1868
+ })
1869
+ );
1845
1870
  }
1846
1871
  async connectNewTabWithUrl(url, options) {
1847
1872
  await this.page.connectNewTabWithUrl(url, options);
@@ -1860,7 +1885,11 @@ var AgentOverChromeBridge = class extends PageAgent {
1860
1885
  return await super.aiAction(prompt);
1861
1886
  }
1862
1887
  };
1888
+
1889
+ // src/bridge-mode/index.ts
1890
+ var import_env4 = require("@midscene/core/env");
1863
1891
  // Annotate the CommonJS export names for ESM import in node:
1864
1892
  0 && (module.exports = {
1865
- AgentOverChromeBridge
1893
+ AgentOverChromeBridge,
1894
+ overrideAIConfig
1866
1895
  });
@@ -697,7 +697,10 @@ var PageTaskExecutor = class {
697
697
  locate: plan2.locate,
698
698
  executor: async (param, taskContext) => {
699
699
  const { task } = taskContext;
700
- (0, import_node_assert2.default)((param == null ? void 0 : param.prompt) || (param == null ? void 0 : param.id), "No prompt or id to locate");
700
+ (0, import_node_assert2.default)(
701
+ (param == null ? void 0 : param.prompt) || (param == null ? void 0 : param.id) || (param == null ? void 0 : param.position),
702
+ "No prompt or id or position to locate"
703
+ );
701
704
  let insightDump;
702
705
  const dumpCollector = (dump) => {
703
706
  insightDump = dump;
@@ -852,6 +855,22 @@ var PageTaskExecutor = class {
852
855
  }
853
856
  };
854
857
  tasks.push(taskActionTap);
858
+ } else if (plan2.type === "Drag") {
859
+ const taskActionDrag = {
860
+ type: "Action",
861
+ subType: "Drag",
862
+ param: plan2.param,
863
+ thought: plan2.thought,
864
+ locate: plan2.locate,
865
+ executor: async (taskParam) => {
866
+ (0, import_node_assert2.default)(
867
+ (taskParam == null ? void 0 : taskParam.start_box) && (taskParam == null ? void 0 : taskParam.end_box),
868
+ "No start_box or end_box to drag"
869
+ );
870
+ await this.page.mouse.drag(taskParam.start_box, taskParam.end_box);
871
+ }
872
+ };
873
+ tasks.push(taskActionDrag);
855
874
  } else if (plan2.type === "Hover") {
856
875
  const taskActionHover = {
857
876
  type: "Action",
@@ -886,9 +905,9 @@ var PageTaskExecutor = class {
886
905
  } else if (scrollToEventName === "untilLeft") {
887
906
  await this.page.scrollUntilLeft(startingPoint);
888
907
  } else if (scrollToEventName === "once" || !scrollToEventName) {
889
- if (taskParam.direction === "down" || !taskParam.direction) {
908
+ if ((taskParam == null ? void 0 : taskParam.direction) === "down" || !taskParam || !taskParam.direction) {
890
909
  await this.page.scrollDown(
891
- taskParam.distance || void 0,
910
+ (taskParam == null ? void 0 : taskParam.distance) || void 0,
892
911
  startingPoint
893
912
  );
894
913
  } else if (taskParam.direction === "up") {
@@ -1083,6 +1102,7 @@ var PageTaskExecutor = class {
1083
1102
  userPrompt
1084
1103
  },
1085
1104
  executor: async (param, executorContext) => {
1105
+ var _a;
1086
1106
  const shotTime = Date.now();
1087
1107
  const pageContext = await this.insight.contextRetrieverFn("locate");
1088
1108
  const recordItem = {
@@ -1119,7 +1139,7 @@ var PageTaskExecutor = class {
1119
1139
  return {
1120
1140
  output: {
1121
1141
  actions,
1122
- thought: actions[0].thought,
1142
+ thought: (_a = actions[0]) == null ? void 0 : _a.thought,
1123
1143
  actionType: actions[0].type,
1124
1144
  taskWillBeAccomplished: false,
1125
1145
  furtherPlan: {
@@ -1623,395 +1643,7 @@ var import_node_assert4 = __toESM(require("assert"));
1623
1643
 
1624
1644
  // src/chrome-extension/cdpInput.ts
1625
1645
  var import_node_assert3 = __toESM(require("assert"));
1626
-
1627
- // src/chrome-extension/USKeyboardLayout.ts
1628
- var _keyDefinitions = {
1629
- "0": { keyCode: 48, key: "0", code: "Digit0" },
1630
- "1": { keyCode: 49, key: "1", code: "Digit1" },
1631
- "2": { keyCode: 50, key: "2", code: "Digit2" },
1632
- "3": { keyCode: 51, key: "3", code: "Digit3" },
1633
- "4": { keyCode: 52, key: "4", code: "Digit4" },
1634
- "5": { keyCode: 53, key: "5", code: "Digit5" },
1635
- "6": { keyCode: 54, key: "6", code: "Digit6" },
1636
- "7": { keyCode: 55, key: "7", code: "Digit7" },
1637
- "8": { keyCode: 56, key: "8", code: "Digit8" },
1638
- "9": { keyCode: 57, key: "9", code: "Digit9" },
1639
- Power: { key: "Power", code: "Power" },
1640
- Eject: { key: "Eject", code: "Eject" },
1641
- Abort: { keyCode: 3, code: "Abort", key: "Cancel" },
1642
- Help: { keyCode: 6, code: "Help", key: "Help" },
1643
- Backspace: { keyCode: 8, code: "Backspace", key: "Backspace" },
1644
- Tab: { keyCode: 9, code: "Tab", key: "Tab" },
1645
- Numpad5: {
1646
- keyCode: 12,
1647
- shiftKeyCode: 101,
1648
- key: "Clear",
1649
- code: "Numpad5",
1650
- shiftKey: "5",
1651
- location: 3
1652
- },
1653
- NumpadEnter: {
1654
- keyCode: 13,
1655
- code: "NumpadEnter",
1656
- key: "Enter",
1657
- text: "\r",
1658
- location: 3
1659
- },
1660
- Enter: { keyCode: 13, code: "Enter", key: "Enter", text: "\r" },
1661
- "\r": { keyCode: 13, code: "Enter", key: "Enter", text: "\r" },
1662
- "\n": { keyCode: 13, code: "Enter", key: "Enter", text: "\r" },
1663
- ShiftLeft: { keyCode: 16, code: "ShiftLeft", key: "Shift", location: 1 },
1664
- ShiftRight: { keyCode: 16, code: "ShiftRight", key: "Shift", location: 2 },
1665
- ControlLeft: {
1666
- keyCode: 17,
1667
- code: "ControlLeft",
1668
- key: "Control",
1669
- location: 1
1670
- },
1671
- ControlRight: {
1672
- keyCode: 17,
1673
- code: "ControlRight",
1674
- key: "Control",
1675
- location: 2
1676
- },
1677
- AltLeft: { keyCode: 18, code: "AltLeft", key: "Alt", location: 1 },
1678
- AltRight: { keyCode: 18, code: "AltRight", key: "Alt", location: 2 },
1679
- Pause: { keyCode: 19, code: "Pause", key: "Pause" },
1680
- CapsLock: { keyCode: 20, code: "CapsLock", key: "CapsLock" },
1681
- Escape: { keyCode: 27, code: "Escape", key: "Escape" },
1682
- Convert: { keyCode: 28, code: "Convert", key: "Convert" },
1683
- NonConvert: { keyCode: 29, code: "NonConvert", key: "NonConvert" },
1684
- Space: { keyCode: 32, code: "Space", key: " " },
1685
- Numpad9: {
1686
- keyCode: 33,
1687
- shiftKeyCode: 105,
1688
- key: "PageUp",
1689
- code: "Numpad9",
1690
- shiftKey: "9",
1691
- location: 3
1692
- },
1693
- PageUp: { keyCode: 33, code: "PageUp", key: "PageUp" },
1694
- Numpad3: {
1695
- keyCode: 34,
1696
- shiftKeyCode: 99,
1697
- key: "PageDown",
1698
- code: "Numpad3",
1699
- shiftKey: "3",
1700
- location: 3
1701
- },
1702
- PageDown: { keyCode: 34, code: "PageDown", key: "PageDown" },
1703
- End: { keyCode: 35, code: "End", key: "End" },
1704
- Numpad1: {
1705
- keyCode: 35,
1706
- shiftKeyCode: 97,
1707
- key: "End",
1708
- code: "Numpad1",
1709
- shiftKey: "1",
1710
- location: 3
1711
- },
1712
- Home: { keyCode: 36, code: "Home", key: "Home" },
1713
- Numpad7: {
1714
- keyCode: 36,
1715
- shiftKeyCode: 103,
1716
- key: "Home",
1717
- code: "Numpad7",
1718
- shiftKey: "7",
1719
- location: 3
1720
- },
1721
- ArrowLeft: { keyCode: 37, code: "ArrowLeft", key: "ArrowLeft" },
1722
- Numpad4: {
1723
- keyCode: 37,
1724
- shiftKeyCode: 100,
1725
- key: "ArrowLeft",
1726
- code: "Numpad4",
1727
- shiftKey: "4",
1728
- location: 3
1729
- },
1730
- Numpad8: {
1731
- keyCode: 38,
1732
- shiftKeyCode: 104,
1733
- key: "ArrowUp",
1734
- code: "Numpad8",
1735
- shiftKey: "8",
1736
- location: 3
1737
- },
1738
- ArrowUp: { keyCode: 38, code: "ArrowUp", key: "ArrowUp" },
1739
- ArrowRight: { keyCode: 39, code: "ArrowRight", key: "ArrowRight" },
1740
- Numpad6: {
1741
- keyCode: 39,
1742
- shiftKeyCode: 102,
1743
- key: "ArrowRight",
1744
- code: "Numpad6",
1745
- shiftKey: "6",
1746
- location: 3
1747
- },
1748
- Numpad2: {
1749
- keyCode: 40,
1750
- shiftKeyCode: 98,
1751
- key: "ArrowDown",
1752
- code: "Numpad2",
1753
- shiftKey: "2",
1754
- location: 3
1755
- },
1756
- ArrowDown: { keyCode: 40, code: "ArrowDown", key: "ArrowDown" },
1757
- Select: { keyCode: 41, code: "Select", key: "Select" },
1758
- Open: { keyCode: 43, code: "Open", key: "Execute" },
1759
- PrintScreen: { keyCode: 44, code: "PrintScreen", key: "PrintScreen" },
1760
- Insert: { keyCode: 45, code: "Insert", key: "Insert" },
1761
- Numpad0: {
1762
- keyCode: 45,
1763
- shiftKeyCode: 96,
1764
- key: "Insert",
1765
- code: "Numpad0",
1766
- shiftKey: "0",
1767
- location: 3
1768
- },
1769
- Delete: { keyCode: 46, code: "Delete", key: "Delete" },
1770
- NumpadDecimal: {
1771
- keyCode: 46,
1772
- shiftKeyCode: 110,
1773
- code: "NumpadDecimal",
1774
- key: "\0",
1775
- shiftKey: ".",
1776
- location: 3
1777
- },
1778
- Digit0: { keyCode: 48, code: "Digit0", shiftKey: ")", key: "0" },
1779
- Digit1: { keyCode: 49, code: "Digit1", shiftKey: "!", key: "1" },
1780
- Digit2: { keyCode: 50, code: "Digit2", shiftKey: "@", key: "2" },
1781
- Digit3: { keyCode: 51, code: "Digit3", shiftKey: "#", key: "3" },
1782
- Digit4: { keyCode: 52, code: "Digit4", shiftKey: "$", key: "4" },
1783
- Digit5: { keyCode: 53, code: "Digit5", shiftKey: "%", key: "5" },
1784
- Digit6: { keyCode: 54, code: "Digit6", shiftKey: "^", key: "6" },
1785
- Digit7: { keyCode: 55, code: "Digit7", shiftKey: "&", key: "7" },
1786
- Digit8: { keyCode: 56, code: "Digit8", shiftKey: "*", key: "8" },
1787
- Digit9: { keyCode: 57, code: "Digit9", shiftKey: "(", key: "9" },
1788
- KeyA: { keyCode: 65, code: "KeyA", shiftKey: "A", key: "a" },
1789
- KeyB: { keyCode: 66, code: "KeyB", shiftKey: "B", key: "b" },
1790
- KeyC: { keyCode: 67, code: "KeyC", shiftKey: "C", key: "c" },
1791
- KeyD: { keyCode: 68, code: "KeyD", shiftKey: "D", key: "d" },
1792
- KeyE: { keyCode: 69, code: "KeyE", shiftKey: "E", key: "e" },
1793
- KeyF: { keyCode: 70, code: "KeyF", shiftKey: "F", key: "f" },
1794
- KeyG: { keyCode: 71, code: "KeyG", shiftKey: "G", key: "g" },
1795
- KeyH: { keyCode: 72, code: "KeyH", shiftKey: "H", key: "h" },
1796
- KeyI: { keyCode: 73, code: "KeyI", shiftKey: "I", key: "i" },
1797
- KeyJ: { keyCode: 74, code: "KeyJ", shiftKey: "J", key: "j" },
1798
- KeyK: { keyCode: 75, code: "KeyK", shiftKey: "K", key: "k" },
1799
- KeyL: { keyCode: 76, code: "KeyL", shiftKey: "L", key: "l" },
1800
- KeyM: { keyCode: 77, code: "KeyM", shiftKey: "M", key: "m" },
1801
- KeyN: { keyCode: 78, code: "KeyN", shiftKey: "N", key: "n" },
1802
- KeyO: { keyCode: 79, code: "KeyO", shiftKey: "O", key: "o" },
1803
- KeyP: { keyCode: 80, code: "KeyP", shiftKey: "P", key: "p" },
1804
- KeyQ: { keyCode: 81, code: "KeyQ", shiftKey: "Q", key: "q" },
1805
- KeyR: { keyCode: 82, code: "KeyR", shiftKey: "R", key: "r" },
1806
- KeyS: { keyCode: 83, code: "KeyS", shiftKey: "S", key: "s" },
1807
- KeyT: { keyCode: 84, code: "KeyT", shiftKey: "T", key: "t" },
1808
- KeyU: { keyCode: 85, code: "KeyU", shiftKey: "U", key: "u" },
1809
- KeyV: { keyCode: 86, code: "KeyV", shiftKey: "V", key: "v" },
1810
- KeyW: { keyCode: 87, code: "KeyW", shiftKey: "W", key: "w" },
1811
- KeyX: { keyCode: 88, code: "KeyX", shiftKey: "X", key: "x" },
1812
- KeyY: { keyCode: 89, code: "KeyY", shiftKey: "Y", key: "y" },
1813
- KeyZ: { keyCode: 90, code: "KeyZ", shiftKey: "Z", key: "z" },
1814
- MetaLeft: { keyCode: 91, code: "MetaLeft", key: "Meta", location: 1 },
1815
- MetaRight: { keyCode: 92, code: "MetaRight", key: "Meta", location: 2 },
1816
- ContextMenu: { keyCode: 93, code: "ContextMenu", key: "ContextMenu" },
1817
- NumpadMultiply: {
1818
- keyCode: 106,
1819
- code: "NumpadMultiply",
1820
- key: "*",
1821
- location: 3
1822
- },
1823
- NumpadAdd: { keyCode: 107, code: "NumpadAdd", key: "+", location: 3 },
1824
- NumpadSubtract: {
1825
- keyCode: 109,
1826
- code: "NumpadSubtract",
1827
- key: "-",
1828
- location: 3
1829
- },
1830
- NumpadDivide: { keyCode: 111, code: "NumpadDivide", key: "/", location: 3 },
1831
- F1: { keyCode: 112, code: "F1", key: "F1" },
1832
- F2: { keyCode: 113, code: "F2", key: "F2" },
1833
- F3: { keyCode: 114, code: "F3", key: "F3" },
1834
- F4: { keyCode: 115, code: "F4", key: "F4" },
1835
- F5: { keyCode: 116, code: "F5", key: "F5" },
1836
- F6: { keyCode: 117, code: "F6", key: "F6" },
1837
- F7: { keyCode: 118, code: "F7", key: "F7" },
1838
- F8: { keyCode: 119, code: "F8", key: "F8" },
1839
- F9: { keyCode: 120, code: "F9", key: "F9" },
1840
- F10: { keyCode: 121, code: "F10", key: "F10" },
1841
- F11: { keyCode: 122, code: "F11", key: "F11" },
1842
- F12: { keyCode: 123, code: "F12", key: "F12" },
1843
- F13: { keyCode: 124, code: "F13", key: "F13" },
1844
- F14: { keyCode: 125, code: "F14", key: "F14" },
1845
- F15: { keyCode: 126, code: "F15", key: "F15" },
1846
- F16: { keyCode: 127, code: "F16", key: "F16" },
1847
- F17: { keyCode: 128, code: "F17", key: "F17" },
1848
- F18: { keyCode: 129, code: "F18", key: "F18" },
1849
- F19: { keyCode: 130, code: "F19", key: "F19" },
1850
- F20: { keyCode: 131, code: "F20", key: "F20" },
1851
- F21: { keyCode: 132, code: "F21", key: "F21" },
1852
- F22: { keyCode: 133, code: "F22", key: "F22" },
1853
- F23: { keyCode: 134, code: "F23", key: "F23" },
1854
- F24: { keyCode: 135, code: "F24", key: "F24" },
1855
- NumLock: { keyCode: 144, code: "NumLock", key: "NumLock" },
1856
- ScrollLock: { keyCode: 145, code: "ScrollLock", key: "ScrollLock" },
1857
- AudioVolumeMute: {
1858
- keyCode: 173,
1859
- code: "AudioVolumeMute",
1860
- key: "AudioVolumeMute"
1861
- },
1862
- AudioVolumeDown: {
1863
- keyCode: 174,
1864
- code: "AudioVolumeDown",
1865
- key: "AudioVolumeDown"
1866
- },
1867
- AudioVolumeUp: { keyCode: 175, code: "AudioVolumeUp", key: "AudioVolumeUp" },
1868
- MediaTrackNext: {
1869
- keyCode: 176,
1870
- code: "MediaTrackNext",
1871
- key: "MediaTrackNext"
1872
- },
1873
- MediaTrackPrevious: {
1874
- keyCode: 177,
1875
- code: "MediaTrackPrevious",
1876
- key: "MediaTrackPrevious"
1877
- },
1878
- MediaStop: { keyCode: 178, code: "MediaStop", key: "MediaStop" },
1879
- MediaPlayPause: {
1880
- keyCode: 179,
1881
- code: "MediaPlayPause",
1882
- key: "MediaPlayPause"
1883
- },
1884
- Semicolon: { keyCode: 186, code: "Semicolon", shiftKey: ":", key: ";" },
1885
- Equal: { keyCode: 187, code: "Equal", shiftKey: "+", key: "=" },
1886
- NumpadEqual: { keyCode: 187, code: "NumpadEqual", key: "=", location: 3 },
1887
- Comma: { keyCode: 188, code: "Comma", shiftKey: "<", key: "," },
1888
- Minus: { keyCode: 189, code: "Minus", shiftKey: "_", key: "-" },
1889
- Period: { keyCode: 190, code: "Period", shiftKey: ">", key: "." },
1890
- Slash: { keyCode: 191, code: "Slash", shiftKey: "?", key: "/" },
1891
- Backquote: { keyCode: 192, code: "Backquote", shiftKey: "~", key: "`" },
1892
- BracketLeft: { keyCode: 219, code: "BracketLeft", shiftKey: "{", key: "[" },
1893
- Backslash: { keyCode: 220, code: "Backslash", shiftKey: "|", key: "\\" },
1894
- BracketRight: { keyCode: 221, code: "BracketRight", shiftKey: "}", key: "]" },
1895
- Quote: { keyCode: 222, code: "Quote", shiftKey: '"', key: "'" },
1896
- AltGraph: { keyCode: 225, code: "AltGraph", key: "AltGraph" },
1897
- Props: { keyCode: 247, code: "Props", key: "CrSel" },
1898
- Cancel: { keyCode: 3, key: "Cancel", code: "Abort" },
1899
- Clear: { keyCode: 12, key: "Clear", code: "Numpad5", location: 3 },
1900
- Shift: { keyCode: 16, key: "Shift", code: "ShiftLeft", location: 1 },
1901
- Control: { keyCode: 17, key: "Control", code: "ControlLeft", location: 1 },
1902
- Alt: { keyCode: 18, key: "Alt", code: "AltLeft", location: 1 },
1903
- Accept: { keyCode: 30, key: "Accept" },
1904
- ModeChange: { keyCode: 31, key: "ModeChange" },
1905
- " ": { keyCode: 32, key: " ", code: "Space" },
1906
- Print: { keyCode: 42, key: "Print" },
1907
- Execute: { keyCode: 43, key: "Execute", code: "Open" },
1908
- "\0": { keyCode: 46, key: "\0", code: "NumpadDecimal", location: 3 },
1909
- a: { keyCode: 65, key: "a", code: "KeyA" },
1910
- b: { keyCode: 66, key: "b", code: "KeyB" },
1911
- c: { keyCode: 67, key: "c", code: "KeyC" },
1912
- d: { keyCode: 68, key: "d", code: "KeyD" },
1913
- e: { keyCode: 69, key: "e", code: "KeyE" },
1914
- f: { keyCode: 70, key: "f", code: "KeyF" },
1915
- g: { keyCode: 71, key: "g", code: "KeyG" },
1916
- h: { keyCode: 72, key: "h", code: "KeyH" },
1917
- i: { keyCode: 73, key: "i", code: "KeyI" },
1918
- j: { keyCode: 74, key: "j", code: "KeyJ" },
1919
- k: { keyCode: 75, key: "k", code: "KeyK" },
1920
- l: { keyCode: 76, key: "l", code: "KeyL" },
1921
- m: { keyCode: 77, key: "m", code: "KeyM" },
1922
- n: { keyCode: 78, key: "n", code: "KeyN" },
1923
- o: { keyCode: 79, key: "o", code: "KeyO" },
1924
- p: { keyCode: 80, key: "p", code: "KeyP" },
1925
- q: { keyCode: 81, key: "q", code: "KeyQ" },
1926
- r: { keyCode: 82, key: "r", code: "KeyR" },
1927
- s: { keyCode: 83, key: "s", code: "KeyS" },
1928
- t: { keyCode: 84, key: "t", code: "KeyT" },
1929
- u: { keyCode: 85, key: "u", code: "KeyU" },
1930
- v: { keyCode: 86, key: "v", code: "KeyV" },
1931
- w: { keyCode: 87, key: "w", code: "KeyW" },
1932
- x: { keyCode: 88, key: "x", code: "KeyX" },
1933
- y: { keyCode: 89, key: "y", code: "KeyY" },
1934
- z: { keyCode: 90, key: "z", code: "KeyZ" },
1935
- Meta: { keyCode: 91, key: "Meta", code: "MetaLeft", location: 1 },
1936
- "*": { keyCode: 106, key: "*", code: "NumpadMultiply", location: 3 },
1937
- "+": { keyCode: 107, key: "+", code: "NumpadAdd", location: 3 },
1938
- "-": { keyCode: 109, key: "-", code: "NumpadSubtract", location: 3 },
1939
- "/": { keyCode: 111, key: "/", code: "NumpadDivide", location: 3 },
1940
- ";": { keyCode: 186, key: ";", code: "Semicolon" },
1941
- "=": { keyCode: 187, key: "=", code: "Equal" },
1942
- ",": { keyCode: 188, key: ",", code: "Comma" },
1943
- ".": { keyCode: 190, key: ".", code: "Period" },
1944
- "`": { keyCode: 192, key: "`", code: "Backquote" },
1945
- "[": { keyCode: 219, key: "[", code: "BracketLeft" },
1946
- "\\": { keyCode: 220, key: "\\", code: "Backslash" },
1947
- "]": { keyCode: 221, key: "]", code: "BracketRight" },
1948
- "'": { keyCode: 222, key: "'", code: "Quote" },
1949
- Attn: { keyCode: 246, key: "Attn" },
1950
- CrSel: { keyCode: 247, key: "CrSel", code: "Props" },
1951
- ExSel: { keyCode: 248, key: "ExSel" },
1952
- EraseEof: { keyCode: 249, key: "EraseEof" },
1953
- Play: { keyCode: 250, key: "Play" },
1954
- ZoomOut: { keyCode: 251, key: "ZoomOut" },
1955
- ")": { keyCode: 48, key: ")", code: "Digit0" },
1956
- "!": { keyCode: 49, key: "!", code: "Digit1" },
1957
- "@": { keyCode: 50, key: "@", code: "Digit2" },
1958
- "#": { keyCode: 51, key: "#", code: "Digit3" },
1959
- $: { keyCode: 52, key: "$", code: "Digit4" },
1960
- "%": { keyCode: 53, key: "%", code: "Digit5" },
1961
- "^": { keyCode: 54, key: "^", code: "Digit6" },
1962
- "&": { keyCode: 55, key: "&", code: "Digit7" },
1963
- "(": { keyCode: 57, key: "(", code: "Digit9" },
1964
- A: { keyCode: 65, key: "A", code: "KeyA" },
1965
- B: { keyCode: 66, key: "B", code: "KeyB" },
1966
- C: { keyCode: 67, key: "C", code: "KeyC" },
1967
- D: { keyCode: 68, key: "D", code: "KeyD" },
1968
- E: { keyCode: 69, key: "E", code: "KeyE" },
1969
- F: { keyCode: 70, key: "F", code: "KeyF" },
1970
- G: { keyCode: 71, key: "G", code: "KeyG" },
1971
- H: { keyCode: 72, key: "H", code: "KeyH" },
1972
- I: { keyCode: 73, key: "I", code: "KeyI" },
1973
- J: { keyCode: 74, key: "J", code: "KeyJ" },
1974
- K: { keyCode: 75, key: "K", code: "KeyK" },
1975
- L: { keyCode: 76, key: "L", code: "KeyL" },
1976
- M: { keyCode: 77, key: "M", code: "KeyM" },
1977
- N: { keyCode: 78, key: "N", code: "KeyN" },
1978
- O: { keyCode: 79, key: "O", code: "KeyO" },
1979
- P: { keyCode: 80, key: "P", code: "KeyP" },
1980
- Q: { keyCode: 81, key: "Q", code: "KeyQ" },
1981
- R: { keyCode: 82, key: "R", code: "KeyR" },
1982
- S: { keyCode: 83, key: "S", code: "KeyS" },
1983
- T: { keyCode: 84, key: "T", code: "KeyT" },
1984
- U: { keyCode: 85, key: "U", code: "KeyU" },
1985
- V: { keyCode: 86, key: "V", code: "KeyV" },
1986
- W: { keyCode: 87, key: "W", code: "KeyW" },
1987
- X: { keyCode: 88, key: "X", code: "KeyX" },
1988
- Y: { keyCode: 89, key: "Y", code: "KeyY" },
1989
- Z: { keyCode: 90, key: "Z", code: "KeyZ" },
1990
- ":": { keyCode: 186, key: ":", code: "Semicolon" },
1991
- "<": { keyCode: 188, key: "<", code: "Comma" },
1992
- _: { keyCode: 189, key: "_", code: "Minus" },
1993
- ">": { keyCode: 190, key: ">", code: "Period" },
1994
- "?": { keyCode: 191, key: "?", code: "Slash" },
1995
- "~": { keyCode: 192, key: "~", code: "Backquote" },
1996
- "{": { keyCode: 219, key: "{", code: "BracketLeft" },
1997
- "|": { keyCode: 220, key: "|", code: "Backslash" },
1998
- "}": { keyCode: 221, key: "}", code: "BracketRight" },
1999
- '"': { keyCode: 222, key: '"', code: "Quote" },
2000
- SoftLeft: { key: "SoftLeft", code: "SoftLeft", location: 4 },
2001
- SoftRight: { key: "SoftRight", code: "SoftRight", location: 4 },
2002
- Camera: { keyCode: 44, key: "Camera", code: "Camera", location: 4 },
2003
- Call: { key: "Call", code: "Call", location: 4 },
2004
- EndCall: { keyCode: 95, key: "EndCall", code: "EndCall", location: 4 },
2005
- VolumeDown: {
2006
- keyCode: 182,
2007
- key: "VolumeDown",
2008
- code: "VolumeDown",
2009
- location: 4
2010
- },
2011
- VolumeUp: { keyCode: 183, key: "VolumeUp", code: "VolumeUp", location: 4 }
2012
- };
2013
-
2014
- // src/chrome-extension/cdpInput.ts
1646
+ var import_keyboard_layout = require("@midscene/shared/keyboard-layout");
2015
1647
  var _pressedKeys, _client, _modifierBit, modifierBit_fn, _keyDescriptionForString, keyDescriptionForString_fn;
2016
1648
  var CdpKeyboard = class {
2017
1649
  constructor(client) {
@@ -2065,7 +1697,7 @@ var CdpKeyboard = class {
2065
1697
  await __privateGet(this, _client).send("Input.insertText", { text: char });
2066
1698
  }
2067
1699
  charIsKey(char) {
2068
- return !!_keyDefinitions[char];
1700
+ return !!import_keyboard_layout._keyDefinitions[char];
2069
1701
  }
2070
1702
  async type(text, options = {}) {
2071
1703
  const delay = options.delay || void 0;
@@ -2084,13 +1716,18 @@ var CdpKeyboard = class {
2084
1716
  }
2085
1717
  async press(key, options = {}) {
2086
1718
  const { delay = null } = options;
2087
- await this.down(key, options);
1719
+ const keys = Array.isArray(key) ? key : [key];
1720
+ for (const k of keys) {
1721
+ await this.down(k, options);
1722
+ }
2088
1723
  if (delay) {
2089
1724
  await new Promise((f) => {
2090
1725
  return setTimeout(f, options.delay);
2091
1726
  });
2092
1727
  }
2093
- await this.up(key);
1728
+ for (const k of [...keys].reverse()) {
1729
+ await this.up(k);
1730
+ }
2094
1731
  }
2095
1732
  };
2096
1733
  _pressedKeys = new WeakMap();
@@ -2121,7 +1758,7 @@ keyDescriptionForString_fn = function(keyString) {
2121
1758
  text: "",
2122
1759
  location: 0
2123
1760
  };
2124
- const definition = _keyDefinitions[keyString];
1761
+ const definition = import_keyboard_layout._keyDefinitions[keyString];
2125
1762
  (0, import_node_assert3.default)(definition, `Unknown key: "${keyString}"`);
2126
1763
  if (definition.key) {
2127
1764
  description.key = definition.key;
@@ -2246,6 +1883,24 @@ var ChromeExtensionProxyPage = class {
2246
1883
  x,
2247
1884
  y
2248
1885
  });
1886
+ },
1887
+ drag: async (from, to) => {
1888
+ await this.mouse.move(from.x, from.y);
1889
+ await this.sendCommandToDebugger("Input.dispatchMouseEvent", {
1890
+ type: "mousePressed",
1891
+ x: from.x,
1892
+ y: from.y,
1893
+ button: "left",
1894
+ clickCount: 1
1895
+ });
1896
+ await this.mouse.move(to.x, to.y);
1897
+ await this.sendCommandToDebugger("Input.dispatchMouseEvent", {
1898
+ type: "mouseReleased",
1899
+ x: to.x,
1900
+ y: to.y,
1901
+ button: "left",
1902
+ clickCount: 1
1903
+ });
2249
1904
  }
2250
1905
  };
2251
1906
  this.keyboard = {
@@ -2259,7 +1914,13 @@ var ChromeExtensionProxyPage = class {
2259
1914
  const cdpKeyboard = new CdpKeyboard({
2260
1915
  send: this.sendCommandToDebugger.bind(this)
2261
1916
  });
2262
- await cdpKeyboard.press(key, { delay: 0 });
1917
+ const keys = Array.isArray(key) ? key : [key];
1918
+ for (const k of keys) {
1919
+ await cdpKeyboard.down(k);
1920
+ }
1921
+ for (const k of [...keys].reverse()) {
1922
+ await cdpKeyboard.up(k);
1923
+ }
2263
1924
  }
2264
1925
  };
2265
1926
  this.trackingActiveTab = trackingActiveTab;