@midscene/web 0.9.2 → 0.10.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.
@@ -57,7 +57,10 @@ __export(browser_exports, {
57
57
  module.exports = __toCommonJS(browser_exports);
58
58
 
59
59
  // src/bridge-mode/page-browser-side.ts
60
- var import_node_assert3 = __toESM(require("assert"));
60
+ var import_node_assert4 = __toESM(require("assert"));
61
+
62
+ // src/chrome-extension/page.ts
63
+ var import_node_assert2 = __toESM(require("assert"));
61
64
 
62
65
  // src/chrome-extension/cdpInput.ts
63
66
  var import_node_assert = __toESM(require("assert"));
@@ -644,9 +647,12 @@ var ChromeExtensionProxyPage = class {
644
647
  constructor(trackingActiveTab) {
645
648
  this.pageType = "chrome-extension-proxy";
646
649
  this.activeTabId = null;
650
+ this.tabIdOfDebuggerAttached = null;
647
651
  this.attachingDebugger = null;
652
+ this.destroyed = false;
648
653
  this.mouse = {
649
654
  click: async (x, y) => {
655
+ await this.showMousePointer(x, y);
650
656
  await this.sendCommandToDebugger("Input.dispatchMouseEvent", {
651
657
  type: "mousePressed",
652
658
  x,
@@ -663,15 +669,19 @@ var ChromeExtensionProxyPage = class {
663
669
  });
664
670
  },
665
671
  wheel: async (deltaX, deltaY, startX, startY) => {
672
+ const finalX = startX || 50;
673
+ const finalY = startY || 50;
674
+ await this.showMousePointer(finalX, finalY);
666
675
  await this.sendCommandToDebugger("Input.dispatchMouseEvent", {
667
676
  type: "mouseWheel",
668
- x: startX || 10,
669
- y: startY || 10,
677
+ x: finalX,
678
+ y: finalY,
670
679
  deltaX,
671
680
  deltaY
672
681
  });
673
682
  },
674
683
  move: async (x, y) => {
684
+ await this.showMousePointer(x, y);
675
685
  await this.sendCommandToDebugger("Input.dispatchMouseEvent", {
676
686
  type: "mouseMoved",
677
687
  x,
@@ -696,8 +706,7 @@ var ChromeExtensionProxyPage = class {
696
706
  this.trackingActiveTab = trackingActiveTab;
697
707
  }
698
708
  async getTabId() {
699
- const trackingActiveTab = this.trackingActiveTab();
700
- if (this.activeTabId && !trackingActiveTab) {
709
+ if (this.activeTabId && !this.trackingActiveTab) {
701
710
  return this.activeTabId;
702
711
  }
703
712
  const tabId = await chrome.tabs.query({ active: true, currentWindow: true }).then((tabs) => {
@@ -708,6 +717,7 @@ var ChromeExtensionProxyPage = class {
708
717
  return this.activeTabId;
709
718
  }
710
719
  async attachDebugger() {
720
+ (0, import_node_assert2.default)(!this.destroyed, "Page is destroyed");
711
721
  if (this.attachingDebugger) {
712
722
  await this.attachingDebugger;
713
723
  return;
@@ -721,52 +731,89 @@ var ChromeExtensionProxyPage = class {
721
731
  }
722
732
  try {
723
733
  const currentTabId = await this.getTabId();
724
- const targets = await chrome.debugger.getTargets();
725
- const target = targets.find(
726
- (target2) => target2.tabId === currentTabId && target2.attached === true
727
- );
728
- if (!target) {
729
- await chrome.debugger.attach({ tabId: currentTabId }, "1.3");
730
- await sleep(340);
734
+ if (this.tabIdOfDebuggerAttached === currentTabId) {
735
+ return;
731
736
  }
737
+ if (this.tabIdOfDebuggerAttached && this.tabIdOfDebuggerAttached !== currentTabId) {
738
+ console.log(
739
+ "detach the previous tab",
740
+ this.tabIdOfDebuggerAttached,
741
+ "->",
742
+ currentTabId
743
+ );
744
+ try {
745
+ await this.detachDebugger(this.tabIdOfDebuggerAttached);
746
+ } catch (error) {
747
+ console.error("Failed to detach debugger", error);
748
+ }
749
+ }
750
+ await chrome.debugger.attach({ tabId: currentTabId }, "1.3");
751
+ await sleep(500);
752
+ this.tabIdOfDebuggerAttached = currentTabId;
753
+ await this.enableWaterFlowAnimation();
754
+ } catch (error) {
755
+ console.error("Failed to attach debugger", error);
732
756
  } finally {
733
757
  this.attachingDebugger = null;
734
758
  }
735
759
  })();
736
760
  await this.attachingDebugger;
737
761
  }
738
- async enableWaterFlowAnimation(tabId) {
739
- const script = await injectWaterFlowAnimation();
740
- await chrome.debugger.sendCommand({ tabId }, "Runtime.evaluate", {
741
- expression: script
762
+ async showMousePointer(x, y) {
763
+ const pointerScript = `(() => {
764
+ if(typeof window.midsceneWaterFlowAnimation !== 'undefined') {
765
+ window.midsceneWaterFlowAnimation.enable();
766
+ window.midsceneWaterFlowAnimation.showMousePointer(${x}, ${y});
767
+ } else {
768
+ console.log('midsceneWaterFlowAnimation is not defined');
769
+ }
770
+ })()`;
771
+ await this.sendCommandToDebugger("Runtime.evaluate", {
772
+ expression: `${pointerScript}`
773
+ });
774
+ }
775
+ async hideMousePointer() {
776
+ await this.sendCommandToDebugger("Runtime.evaluate", {
777
+ expression: `(() => {
778
+ if(typeof window.midsceneWaterFlowAnimation !== 'undefined') {
779
+ window.midsceneWaterFlowAnimation.hideMousePointer();
780
+ }
781
+ })()`
742
782
  });
743
783
  }
784
+ async detachDebugger(tabId) {
785
+ const tabIdToDetach = tabId || this.tabIdOfDebuggerAttached;
786
+ if (!tabIdToDetach) {
787
+ console.warn("No tab id to detach");
788
+ return;
789
+ }
790
+ await this.disableWaterFlowAnimation(tabIdToDetach);
791
+ await sleep(200);
792
+ await chrome.debugger.detach({ tabId: tabIdToDetach });
793
+ this.tabIdOfDebuggerAttached = null;
794
+ }
795
+ async enableWaterFlowAnimation() {
796
+ const script = await injectWaterFlowAnimation();
797
+ await chrome.debugger.sendCommand(
798
+ { tabId: this.tabIdOfDebuggerAttached },
799
+ "Runtime.evaluate",
800
+ {
801
+ expression: script
802
+ }
803
+ );
804
+ }
744
805
  async disableWaterFlowAnimation(tabId) {
745
806
  const script = await injectStopWaterFlowAnimation();
746
807
  await chrome.debugger.sendCommand({ tabId }, "Runtime.evaluate", {
747
808
  expression: script
748
809
  });
749
810
  }
750
- async detachDebugger() {
751
- const targets = await chrome.debugger.getTargets();
752
- const attendTabs = targets.filter(
753
- (target) => target.attached === true && !target.url.startsWith("chrome-extension://")
754
- );
755
- if (attendTabs.length > 0) {
756
- for (const tab of attendTabs) {
757
- if (tab.tabId) {
758
- await this.disableWaterFlowAnimation(tab.tabId);
759
- chrome.debugger.detach({ tabId: tab.tabId });
760
- }
761
- }
762
- }
763
- }
764
811
  async sendCommandToDebugger(command, params) {
765
812
  await this.attachDebugger();
766
- const tabId = await this.getTabId();
767
- this.enableWaterFlowAnimation(tabId);
813
+ (0, import_node_assert2.default)(this.tabIdOfDebuggerAttached, "Debugger is not attached");
814
+ this.enableWaterFlowAnimation();
768
815
  return await chrome.debugger.sendCommand(
769
- { tabId },
816
+ { tabId: this.tabIdOfDebuggerAttached },
770
817
  command,
771
818
  params
772
819
  );
@@ -823,6 +870,7 @@ var ChromeExtensionProxyPage = class {
823
870
  );
824
871
  }
825
872
  async getElementInfos() {
873
+ await this.hideMousePointer();
826
874
  const content = await this.getPageContentByCDP();
827
875
  if (content == null ? void 0 : content.size) {
828
876
  this.viewportSize = content.size;
@@ -836,6 +884,7 @@ var ChromeExtensionProxyPage = class {
836
884
  return content.size;
837
885
  }
838
886
  async screenshotBase64() {
887
+ await this.hideMousePointer();
839
888
  const base64 = await this.sendCommandToDebugger("Page.captureScreenshot", {
840
889
  format: "jpeg",
841
890
  quality: 70
@@ -935,6 +984,7 @@ var ChromeExtensionProxyPage = class {
935
984
  async destroy() {
936
985
  this.activeTabId = null;
937
986
  await this.detachDebugger();
987
+ this.destroyed = true;
938
988
  }
939
989
  };
940
990
 
@@ -943,7 +993,7 @@ var DefaultBridgeServerPort = 3766;
943
993
  var DefaultLocalEndpoint = `http://127.0.0.1:${DefaultBridgeServerPort}`;
944
994
 
945
995
  // src/bridge-mode/io-client.ts
946
- var import_node_assert2 = __toESM(require("assert"));
996
+ var import_node_assert3 = __toESM(require("assert"));
947
997
  var import_socket = require("socket.io-client");
948
998
  var BridgeClient = class {
949
999
  constructor(endpoint, onBridgeCall, onDisconnect) {
@@ -958,7 +1008,7 @@ var BridgeClient = class {
958
1008
  this.socket = (0, import_socket.io)(this.endpoint, {
959
1009
  reconnection: false,
960
1010
  query: {
961
- version: "0.9.2"
1011
+ version: "0.10.0"
962
1012
  }
963
1013
  });
964
1014
  const timeout = setTimeout(() => {
@@ -983,7 +1033,7 @@ var BridgeClient = class {
983
1033
  });
984
1034
  this.socket.on("bridge-call" /* Call */, (call) => {
985
1035
  const id = call.id;
986
- (0, import_node_assert2.default)(typeof id !== "undefined", "call id is required");
1036
+ (0, import_node_assert3.default)(typeof id !== "undefined", "call id is required");
987
1037
  Promise.resolve().then(async () => {
988
1038
  var _a, _b;
989
1039
  let response;
@@ -1017,8 +1067,8 @@ ${(e == null ? void 0 : e.stack) || ""}`;
1017
1067
  var ChromeExtensionPageBrowserSide = class extends ChromeExtensionProxyPage {
1018
1068
  constructor(onDisconnect = () => {
1019
1069
  }, onLogMessage = () => {
1020
- }) {
1021
- super(() => true);
1070
+ }, trackingActiveTab = false) {
1071
+ super(trackingActiveTab);
1022
1072
  this.onDisconnect = onDisconnect;
1023
1073
  this.onLogMessage = onLogMessage;
1024
1074
  this.bridgeClient = null;
@@ -1074,26 +1124,32 @@ var ChromeExtensionPageBrowserSide = class extends ChromeExtensionProxyPage {
1074
1124
  );
1075
1125
  await this.bridgeClient.connect();
1076
1126
  this.onLogMessage(
1077
- `Bridge connected, cli-side version v${this.bridgeClient.serverVersion}, browser-side version v${"0.9.2"}`,
1127
+ `Bridge connected, cli-side version v${this.bridgeClient.serverVersion}, browser-side version v${"0.10.0"}`,
1078
1128
  "log"
1079
1129
  );
1080
1130
  }
1081
1131
  async connect() {
1082
1132
  return await this.setupBridgeClient();
1083
1133
  }
1084
- async connectNewTabWithUrl(url) {
1134
+ async connectNewTabWithUrl(url, options) {
1085
1135
  const tab = await chrome.tabs.create({ url });
1086
1136
  const tabId = tab.id;
1087
- (0, import_node_assert3.default)(tabId, "failed to get tabId after creating a new tab");
1137
+ (0, import_node_assert4.default)(tabId, "failed to get tabId after creating a new tab");
1088
1138
  this.onLogMessage(`Creating new tab: ${url}`, "log");
1139
+ if (options == null ? void 0 : options.trackingActiveTab) {
1140
+ this.trackingActiveTab = true;
1141
+ }
1089
1142
  }
1090
- async connectCurrentTab() {
1143
+ async connectCurrentTab(options) {
1091
1144
  var _a, _b;
1092
1145
  const tabs = await chrome.tabs.query({ active: true, currentWindow: true });
1093
1146
  console.log("current tab", tabs);
1094
1147
  const tabId = (_a = tabs[0]) == null ? void 0 : _a.id;
1095
- (0, import_node_assert3.default)(tabId, "failed to get tabId");
1148
+ (0, import_node_assert4.default)(tabId, "failed to get tabId");
1096
1149
  this.onLogMessage(`Connected to current tab: ${(_b = tabs[0]) == null ? void 0 : _b.url}`, "log");
1150
+ if (options == null ? void 0 : options.trackingActiveTab) {
1151
+ this.trackingActiveTab = true;
1152
+ }
1097
1153
  }
1098
1154
  async destroy() {
1099
1155
  if (this.bridgeClient) {
@@ -1649,7 +1649,7 @@ var BridgeServer = class {
1649
1649
  this.socket = socket;
1650
1650
  const clientVersion = socket.handshake.query.version;
1651
1651
  console.log(
1652
- `Bridge connected, cli-side version v${"0.9.2"}, browser-side version v${clientVersion}`
1652
+ `Bridge connected, cli-side version v${"0.10.0"}, browser-side version v${clientVersion}`
1653
1653
  );
1654
1654
  socket.on("bridge-call-response" /* CallResponse */, (params) => {
1655
1655
  const id = params.id;
@@ -1682,7 +1682,7 @@ var BridgeServer = class {
1682
1682
  var _a;
1683
1683
  (_a = this.onConnect) == null ? void 0 : _a.call(this);
1684
1684
  const payload = {
1685
- version: "0.9.2"
1685
+ version: "0.10.0"
1686
1686
  };
1687
1687
  socket.emit("bridge-connected" /* Connected */, payload);
1688
1688
  Promise.resolve().then(() => {
@@ -1771,6 +1771,7 @@ var BridgeServer = class {
1771
1771
  };
1772
1772
 
1773
1773
  // src/bridge-mode/agent-cli-side.ts
1774
+ var sleep2 = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
1774
1775
  var getBridgePageInCliSide = () => {
1775
1776
  const server = new BridgeServer(DefaultBridgeServerPort);
1776
1777
  server.listen();
@@ -1842,11 +1843,13 @@ var AgentOverChromeBridge = class extends PageAgent {
1842
1843
  }
1843
1844
  });
1844
1845
  }
1845
- async connectNewTabWithUrl(url) {
1846
- await this.page.connectNewTabWithUrl(url);
1846
+ async connectNewTabWithUrl(url, options) {
1847
+ await this.page.connectNewTabWithUrl(url, options);
1848
+ await sleep2(500);
1847
1849
  }
1848
- async connectCurrentTab() {
1849
- await this.page.connectCurrentTab();
1850
+ async connectCurrentTab(options) {
1851
+ await this.page.connectCurrentTab(options);
1852
+ await sleep2(500);
1850
1853
  }
1851
1854
  async aiAction(prompt, options) {
1852
1855
  if (options) {
@@ -1618,6 +1618,9 @@ var ChromeExtensionProxyPageAgent = class extends PageAgent {
1618
1618
  }
1619
1619
  };
1620
1620
 
1621
+ // src/chrome-extension/page.ts
1622
+ var import_node_assert4 = __toESM(require("assert"));
1623
+
1621
1624
  // src/chrome-extension/cdpInput.ts
1622
1625
  var import_node_assert3 = __toESM(require("assert"));
1623
1626
 
@@ -2203,9 +2206,12 @@ var ChromeExtensionProxyPage = class {
2203
2206
  constructor(trackingActiveTab) {
2204
2207
  this.pageType = "chrome-extension-proxy";
2205
2208
  this.activeTabId = null;
2209
+ this.tabIdOfDebuggerAttached = null;
2206
2210
  this.attachingDebugger = null;
2211
+ this.destroyed = false;
2207
2212
  this.mouse = {
2208
2213
  click: async (x, y) => {
2214
+ await this.showMousePointer(x, y);
2209
2215
  await this.sendCommandToDebugger("Input.dispatchMouseEvent", {
2210
2216
  type: "mousePressed",
2211
2217
  x,
@@ -2222,15 +2228,19 @@ var ChromeExtensionProxyPage = class {
2222
2228
  });
2223
2229
  },
2224
2230
  wheel: async (deltaX, deltaY, startX, startY) => {
2231
+ const finalX = startX || 50;
2232
+ const finalY = startY || 50;
2233
+ await this.showMousePointer(finalX, finalY);
2225
2234
  await this.sendCommandToDebugger("Input.dispatchMouseEvent", {
2226
2235
  type: "mouseWheel",
2227
- x: startX || 10,
2228
- y: startY || 10,
2236
+ x: finalX,
2237
+ y: finalY,
2229
2238
  deltaX,
2230
2239
  deltaY
2231
2240
  });
2232
2241
  },
2233
2242
  move: async (x, y) => {
2243
+ await this.showMousePointer(x, y);
2234
2244
  await this.sendCommandToDebugger("Input.dispatchMouseEvent", {
2235
2245
  type: "mouseMoved",
2236
2246
  x,
@@ -2255,8 +2265,7 @@ var ChromeExtensionProxyPage = class {
2255
2265
  this.trackingActiveTab = trackingActiveTab;
2256
2266
  }
2257
2267
  async getTabId() {
2258
- const trackingActiveTab = this.trackingActiveTab();
2259
- if (this.activeTabId && !trackingActiveTab) {
2268
+ if (this.activeTabId && !this.trackingActiveTab) {
2260
2269
  return this.activeTabId;
2261
2270
  }
2262
2271
  const tabId = await chrome.tabs.query({ active: true, currentWindow: true }).then((tabs) => {
@@ -2267,6 +2276,7 @@ var ChromeExtensionProxyPage = class {
2267
2276
  return this.activeTabId;
2268
2277
  }
2269
2278
  async attachDebugger() {
2279
+ (0, import_node_assert4.default)(!this.destroyed, "Page is destroyed");
2270
2280
  if (this.attachingDebugger) {
2271
2281
  await this.attachingDebugger;
2272
2282
  return;
@@ -2280,52 +2290,89 @@ var ChromeExtensionProxyPage = class {
2280
2290
  }
2281
2291
  try {
2282
2292
  const currentTabId = await this.getTabId();
2283
- const targets = await chrome.debugger.getTargets();
2284
- const target = targets.find(
2285
- (target2) => target2.tabId === currentTabId && target2.attached === true
2286
- );
2287
- if (!target) {
2288
- await chrome.debugger.attach({ tabId: currentTabId }, "1.3");
2289
- await sleep2(340);
2293
+ if (this.tabIdOfDebuggerAttached === currentTabId) {
2294
+ return;
2290
2295
  }
2296
+ if (this.tabIdOfDebuggerAttached && this.tabIdOfDebuggerAttached !== currentTabId) {
2297
+ console.log(
2298
+ "detach the previous tab",
2299
+ this.tabIdOfDebuggerAttached,
2300
+ "->",
2301
+ currentTabId
2302
+ );
2303
+ try {
2304
+ await this.detachDebugger(this.tabIdOfDebuggerAttached);
2305
+ } catch (error) {
2306
+ console.error("Failed to detach debugger", error);
2307
+ }
2308
+ }
2309
+ await chrome.debugger.attach({ tabId: currentTabId }, "1.3");
2310
+ await sleep2(500);
2311
+ this.tabIdOfDebuggerAttached = currentTabId;
2312
+ await this.enableWaterFlowAnimation();
2313
+ } catch (error) {
2314
+ console.error("Failed to attach debugger", error);
2291
2315
  } finally {
2292
2316
  this.attachingDebugger = null;
2293
2317
  }
2294
2318
  })();
2295
2319
  await this.attachingDebugger;
2296
2320
  }
2297
- async enableWaterFlowAnimation(tabId) {
2298
- const script = await injectWaterFlowAnimation();
2299
- await chrome.debugger.sendCommand({ tabId }, "Runtime.evaluate", {
2300
- expression: script
2321
+ async showMousePointer(x, y) {
2322
+ const pointerScript = `(() => {
2323
+ if(typeof window.midsceneWaterFlowAnimation !== 'undefined') {
2324
+ window.midsceneWaterFlowAnimation.enable();
2325
+ window.midsceneWaterFlowAnimation.showMousePointer(${x}, ${y});
2326
+ } else {
2327
+ console.log('midsceneWaterFlowAnimation is not defined');
2328
+ }
2329
+ })()`;
2330
+ await this.sendCommandToDebugger("Runtime.evaluate", {
2331
+ expression: `${pointerScript}`
2332
+ });
2333
+ }
2334
+ async hideMousePointer() {
2335
+ await this.sendCommandToDebugger("Runtime.evaluate", {
2336
+ expression: `(() => {
2337
+ if(typeof window.midsceneWaterFlowAnimation !== 'undefined') {
2338
+ window.midsceneWaterFlowAnimation.hideMousePointer();
2339
+ }
2340
+ })()`
2301
2341
  });
2302
2342
  }
2343
+ async detachDebugger(tabId) {
2344
+ const tabIdToDetach = tabId || this.tabIdOfDebuggerAttached;
2345
+ if (!tabIdToDetach) {
2346
+ console.warn("No tab id to detach");
2347
+ return;
2348
+ }
2349
+ await this.disableWaterFlowAnimation(tabIdToDetach);
2350
+ await sleep2(200);
2351
+ await chrome.debugger.detach({ tabId: tabIdToDetach });
2352
+ this.tabIdOfDebuggerAttached = null;
2353
+ }
2354
+ async enableWaterFlowAnimation() {
2355
+ const script = await injectWaterFlowAnimation();
2356
+ await chrome.debugger.sendCommand(
2357
+ { tabId: this.tabIdOfDebuggerAttached },
2358
+ "Runtime.evaluate",
2359
+ {
2360
+ expression: script
2361
+ }
2362
+ );
2363
+ }
2303
2364
  async disableWaterFlowAnimation(tabId) {
2304
2365
  const script = await injectStopWaterFlowAnimation();
2305
2366
  await chrome.debugger.sendCommand({ tabId }, "Runtime.evaluate", {
2306
2367
  expression: script
2307
2368
  });
2308
2369
  }
2309
- async detachDebugger() {
2310
- const targets = await chrome.debugger.getTargets();
2311
- const attendTabs = targets.filter(
2312
- (target) => target.attached === true && !target.url.startsWith("chrome-extension://")
2313
- );
2314
- if (attendTabs.length > 0) {
2315
- for (const tab of attendTabs) {
2316
- if (tab.tabId) {
2317
- await this.disableWaterFlowAnimation(tab.tabId);
2318
- chrome.debugger.detach({ tabId: tab.tabId });
2319
- }
2320
- }
2321
- }
2322
- }
2323
2370
  async sendCommandToDebugger(command, params) {
2324
2371
  await this.attachDebugger();
2325
- const tabId = await this.getTabId();
2326
- this.enableWaterFlowAnimation(tabId);
2372
+ (0, import_node_assert4.default)(this.tabIdOfDebuggerAttached, "Debugger is not attached");
2373
+ this.enableWaterFlowAnimation();
2327
2374
  return await chrome.debugger.sendCommand(
2328
- { tabId },
2375
+ { tabId: this.tabIdOfDebuggerAttached },
2329
2376
  command,
2330
2377
  params
2331
2378
  );
@@ -2382,6 +2429,7 @@ var ChromeExtensionProxyPage = class {
2382
2429
  );
2383
2430
  }
2384
2431
  async getElementInfos() {
2432
+ await this.hideMousePointer();
2385
2433
  const content = await this.getPageContentByCDP();
2386
2434
  if (content == null ? void 0 : content.size) {
2387
2435
  this.viewportSize = content.size;
@@ -2395,6 +2443,7 @@ var ChromeExtensionProxyPage = class {
2395
2443
  return content.size;
2396
2444
  }
2397
2445
  async screenshotBase64() {
2446
+ await this.hideMousePointer();
2398
2447
  const base64 = await this.sendCommandToDebugger("Page.captureScreenshot", {
2399
2448
  format: "jpeg",
2400
2449
  quality: 70
@@ -2494,6 +2543,7 @@ var ChromeExtensionProxyPage = class {
2494
2543
  async destroy() {
2495
2544
  this.activeTabId = null;
2496
2545
  await this.detachDebugger();
2546
+ this.destroyed = true;
2497
2547
  }
2498
2548
  };
2499
2549
  // Annotate the CommonJS export names for ESM import in node:
package/dist/es/index.js CHANGED
@@ -1845,61 +1845,53 @@ var Page = class {
1845
1845
  }
1846
1846
  await this.keyboard.press("Backspace");
1847
1847
  }
1848
- async scrollUntilTop(startingPoint) {
1849
- if (startingPoint) {
1850
- await this.mouse.move(startingPoint.left, startingPoint.top);
1848
+ async moveToPoint(point) {
1849
+ if (point) {
1850
+ await this.mouse.move(point.left, point.top);
1851
+ } else {
1852
+ const size = await this.size();
1853
+ await this.mouse.move(size.width / 2, size.height / 2);
1851
1854
  }
1855
+ }
1856
+ async scrollUntilTop(startingPoint) {
1857
+ await this.moveToPoint(startingPoint);
1852
1858
  return this.mouse.wheel(0, -9999999);
1853
1859
  }
1854
1860
  async scrollUntilBottom(startingPoint) {
1855
- if (startingPoint) {
1856
- await this.mouse.move(startingPoint.left, startingPoint.top);
1857
- }
1861
+ await this.moveToPoint(startingPoint);
1858
1862
  return this.mouse.wheel(0, 9999999);
1859
1863
  }
1860
1864
  async scrollUntilLeft(startingPoint) {
1861
- if (startingPoint) {
1862
- await this.mouse.move(startingPoint.left, startingPoint.top);
1863
- }
1865
+ await this.moveToPoint(startingPoint);
1864
1866
  return this.mouse.wheel(-9999999, 0);
1865
1867
  }
1866
1868
  async scrollUntilRight(startingPoint) {
1867
- if (startingPoint) {
1868
- await this.mouse.move(startingPoint.left, startingPoint.top);
1869
- }
1869
+ await this.moveToPoint(startingPoint);
1870
1870
  return this.mouse.wheel(9999999, 0);
1871
1871
  }
1872
1872
  async scrollUp(distance, startingPoint) {
1873
1873
  const innerHeight = await this.evaluate(() => window.innerHeight);
1874
1874
  const scrollDistance = distance || innerHeight * 0.7;
1875
- if (startingPoint) {
1876
- await this.mouse.move(startingPoint.left, startingPoint.top);
1877
- }
1878
- await this.mouse.wheel(0, -scrollDistance);
1875
+ await this.moveToPoint(startingPoint);
1876
+ return this.mouse.wheel(0, -scrollDistance);
1879
1877
  }
1880
1878
  async scrollDown(distance, startingPoint) {
1881
1879
  const innerHeight = await this.evaluate(() => window.innerHeight);
1882
1880
  const scrollDistance = distance || innerHeight * 0.7;
1883
- if (startingPoint) {
1884
- await this.mouse.move(startingPoint.left, startingPoint.top);
1885
- }
1886
- await this.mouse.wheel(0, scrollDistance);
1881
+ await this.moveToPoint(startingPoint);
1882
+ return this.mouse.wheel(0, scrollDistance);
1887
1883
  }
1888
1884
  async scrollLeft(distance, startingPoint) {
1889
1885
  const innerWidth = await this.evaluate(() => window.innerWidth);
1890
1886
  const scrollDistance = distance || innerWidth * 0.7;
1891
- if (startingPoint) {
1892
- await this.mouse.move(startingPoint.left, startingPoint.top);
1893
- }
1894
- await this.mouse.wheel(-scrollDistance, 0);
1887
+ await this.moveToPoint(startingPoint);
1888
+ return this.mouse.wheel(-scrollDistance, 0);
1895
1889
  }
1896
1890
  async scrollRight(distance, startingPoint) {
1897
1891
  const innerWidth = await this.evaluate(() => window.innerWidth);
1898
1892
  const scrollDistance = distance || innerWidth * 0.7;
1899
- if (startingPoint) {
1900
- await this.mouse.move(startingPoint.left, startingPoint.top);
1901
- }
1902
- await this.mouse.wheel(scrollDistance, 0);
1893
+ await this.moveToPoint(startingPoint);
1894
+ return this.mouse.wheel(scrollDistance, 0);
1903
1895
  }
1904
1896
  async destroy() {
1905
1897
  }