@midscene/android 1.17.8-beta-20261106101231.0 → 1.17.8

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.
@@ -1,105 +1 @@
1
- import { createAgentTestRunnerNodeDefinition } from "@midscene/core/agent/test";
2
- import { z } from "zod/v4";
3
- const defineAndroidAgentNode = createAgentTestRunnerNodeDefinition('an Android Agent');
4
- const nonBlankText = (description)=>z.string().regex(/\S/, 'value must contain a non-whitespace character').describe(description);
5
- const launchInputSchema = z.strictObject({
6
- uri: nonBlankText('The app, URL, URI, or package name to launch.')
7
- });
8
- const terminateInputSchema = z.strictObject({
9
- uri: nonBlankText('The package name or app name to terminate.')
10
- });
11
- const runAdbShellOptionsInputSchema = z.strictObject({
12
- timeout: z.number().int().positive().optional().describe('ADB shell command timeout in milliseconds.')
13
- });
14
- const runAdbShellInputSchema = z.strictObject({
15
- command: nonBlankText('The shell command to execute, without an adb shell prefix.'),
16
- options: runAdbShellOptionsInputSchema.optional()
17
- });
18
- const emptyInputSchema = z.strictObject({});
19
- const launchNode = defineAndroidAgentNode({
20
- method: 'launch',
21
- description: 'Launch an application through the current Android Agent.',
22
- stringInputKey: 'uri',
23
- inputSchema: launchInputSchema,
24
- toArgs: (input)=>[
25
- input.uri
26
- ],
27
- toResult: (_output, input)=>({
28
- summary: `Launched ${input.uri}`
29
- })
30
- });
31
- const terminateNode = defineAndroidAgentNode({
32
- method: 'terminate',
33
- description: 'Terminate an application through the current Android Agent.',
34
- stringInputKey: 'uri',
35
- inputSchema: terminateInputSchema,
36
- toArgs: (input)=>[
37
- input.uri
38
- ],
39
- toResult: (_output, input)=>({
40
- summary: `Terminated ${input.uri}`
41
- })
42
- });
43
- const runAdbShellNode = defineAndroidAgentNode({
44
- method: 'runAdbShell',
45
- title: 'Run an ADB shell command',
46
- description: 'Execute a shell command through the current Android Agent. Pass only the shell command, without the adb shell prefix.',
47
- stringInputKey: 'command',
48
- inputSchema: runAdbShellInputSchema,
49
- toArgs (input, context) {
50
- context.signal.throwIfAborted();
51
- if (/^\s*adb(?:\s|$)/i.test(input.command)) throw new TypeError('command must not include an adb or adb shell prefix.');
52
- return [
53
- input.command,
54
- input.options
55
- ];
56
- },
57
- toResult (stdout) {
58
- if ('string' != typeof stdout) throw new TypeError('runAdbShell() must return stdout as a string.');
59
- return {
60
- summary: `Executed ADB shell command (${stdout.length} stdout characters)`,
61
- data: {
62
- stdout
63
- }
64
- };
65
- }
66
- });
67
- const backNode = defineAndroidAgentNode({
68
- method: 'back',
69
- description: 'Trigger the Android system back operation.',
70
- stringInputKey: false,
71
- inputSchema: emptyInputSchema,
72
- toArgs: ()=>[],
73
- toResult: ()=>({
74
- summary: 'Triggered Android back'
75
- })
76
- });
77
- const homeNode = defineAndroidAgentNode({
78
- method: 'home',
79
- description: 'Trigger the Android system home operation.',
80
- stringInputKey: false,
81
- inputSchema: emptyInputSchema,
82
- toArgs: ()=>[],
83
- toResult: ()=>({
84
- summary: 'Triggered Android home'
85
- })
86
- });
87
- const recentAppsNode = defineAndroidAgentNode({
88
- method: 'recentApps',
89
- description: 'Trigger the Android system recent apps operation.',
90
- stringInputKey: false,
91
- inputSchema: emptyInputSchema,
92
- toArgs: ()=>[],
93
- toResult: ()=>({
94
- summary: 'Triggered Android recentApps'
95
- })
96
- });
97
- const androidAgentTestRunnerNodeDefinitions = [
98
- launchNode,
99
- terminateNode,
100
- runAdbShellNode,
101
- backNode,
102
- homeNode,
103
- recentAppsNode
104
- ];
105
- export { androidAgentTestRunnerNodeDefinitions, launchInputSchema, runAdbShellInputSchema, runAdbShellOptionsInputSchema, terminateInputSchema };
1
+ export { androidAgentTestRunnerNodeDefinitions, launchInputSchema, runAdbShellInputSchema, runAdbShellOptionsInputSchema, terminateInputSchema } from "./140.mjs";
package/dist/lib/cli.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  const __rslib_import_meta_url__ = /*#__PURE__*/ function() {
3
- return 'undefined' == typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
3
+ return "u" < typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
4
4
  }();
5
5
  var __webpack_modules__ = {
6
6
  "./src/resource-path.ts" (__unused_rspack_module, __webpack_exports__, __webpack_require__) {
@@ -553,7 +553,7 @@ var __webpack_modules__ = {
553
553
  const activeReset = this.videoResetState;
554
554
  if (activeReset) {
555
555
  if (activeReset.writePromise) await this.waitForVideoResetWrite(activeReset.writePromise, deadlineAt);
556
- return;
556
+ return activeReset;
557
557
  }
558
558
  const controller = this.scrcpyClient?.controller;
559
559
  if (!controller?.resetVideo) throw new Error('Scrcpy control channel is unavailable for video reset');
@@ -583,6 +583,7 @@ var __webpack_modules__ = {
583
583
  resetState.writePromise = resetPromise;
584
584
  resetPromise.catch(()=>{});
585
585
  await this.waitForVideoResetWrite(resetPromise, deadlineAt);
586
+ return resetState;
586
587
  }
587
588
  async waitForVideoResetWrite(writePromise, deadlineAt) {
588
589
  const remainingMs = deadlineAt - Date.now();
@@ -643,8 +644,7 @@ var __webpack_modules__ = {
643
644
  }
644
645
  async isPlanningCandidateFreshEnough(candidate) {
645
646
  if (void 0 === candidate.ptsUs) throw new Error('Scrcpy frame has no PTS metadata; cannot prove planning freshness');
646
- const ageEvaluatedAtUs = this.monotonicTimeUs();
647
- let age = this.estimateFrameAge(candidate.ptsUs, ageEvaluatedAtUs);
647
+ let age = this.estimateFrameAge(candidate.ptsUs, this.monotonicTimeUs());
648
648
  if (null === age) throw new Error('Scrcpy frame clock is not calibrated; cannot prove planning freshness');
649
649
  if (age.upperBoundUs <= MAX_FRAME_AGE_US) return true;
650
650
  const uncertaintyOnlyExceededLimit = age.estimatedAgeUs <= MAX_FRAME_AGE_US && age.upperBoundUs > MAX_FRAME_AGE_US;
@@ -658,8 +658,9 @@ var __webpack_modules__ = {
658
658
  debugScrcpy(`Unable to recalibrate scrcpy frame clock after an uncertainty-only freshness result: ${error}`);
659
659
  }
660
660
  if (void 0 !== candidate.streamEpoch && candidate.streamEpoch !== this.streamEpoch) throw new Error('Scrcpy stream epoch changed while recalibrating planning frame freshness');
661
- const recalibratedAge = this.estimateFrameAge(candidate.ptsUs, ageEvaluatedAtUs);
662
- if (recalibratedAge) age = recalibratedAge;
661
+ const recalibratedAge = this.estimateFrameAge(candidate.ptsUs, this.monotonicTimeUs());
662
+ if (!recalibratedAge) throw new Error('Scrcpy frame clock is not calibrated; cannot prove planning freshness');
663
+ age = recalibratedAge;
663
664
  if (age.upperBoundUs <= MAX_FRAME_AGE_US) {
664
665
  debugScrcpy(`Planning candidate PTS ${candidate.ptsUs}µs accepted after clock recalibration (estimated=${Number(age.estimatedAgeUs) / 1000}ms, uncertainty<=${Number(age.calibrationUncertaintyUs) / 1000}ms)`);
665
666
  return true;
@@ -676,7 +677,7 @@ var __webpack_modules__ = {
676
677
  async waitForPlanningFrame() {
677
678
  let planningBarrierArmed = false;
678
679
  let videoResetAttempted = false;
679
- let videoResetWritten = false;
680
+ let videoReset = null;
680
681
  const planningStartedAt = Date.now();
681
682
  const startupWindowRemainingMs = this.streamStartupWindow ? this.streamStartupWindow.deadlineAt - planningStartedAt : 0;
682
683
  if (this.streamStartupWindow && startupWindowRemainingMs <= 0) this.streamStartupWindow = null;
@@ -694,7 +695,7 @@ var __webpack_modules__ = {
694
695
  }
695
696
  const remainingMs = deadline - Date.now();
696
697
  if (remainingMs <= 0) {
697
- if (videoResetWritten) throw this.createVideoResetFrameTimeoutError();
698
+ if (videoReset) throw this.createVideoResetFrameTimeoutError(videoReset);
698
699
  throw new Error(`No scrcpy frame crossed the active freshness target within ${FRESH_FRAME_TIMEOUT_MS}ms`);
699
700
  }
700
701
  const shouldTryVideoReset = !videoResetAttempted && this.hasEstablishedVideoFrame && null === this.streamStartupWindow && Boolean(this.scrcpyClient?.controller?.resetVideo) && remainingMs > VIDEO_RESET_DELAY_MS;
@@ -703,13 +704,12 @@ var __webpack_modules__ = {
703
704
  candidate = await this.waitForNextKeyframe(nextFrameWaitMs);
704
705
  } catch (error) {
705
706
  if (!shouldTryVideoReset) {
706
- if (videoResetWritten) throw this.createVideoResetFrameTimeoutError();
707
+ if (videoReset) throw this.createVideoResetFrameTimeoutError(videoReset);
707
708
  throw error;
708
709
  }
709
710
  videoResetAttempted = true;
710
711
  try {
711
- await this.requestVideoReset(deadline);
712
- videoResetWritten = true;
712
+ videoReset = await this.requestVideoReset(deadline);
713
713
  deadline = Date.now() + this.options.videoResetFrameTimeoutMs;
714
714
  debugScrcpy(`Scrcpy video reset control write completed; waiting up to ${this.options.videoResetFrameTimeoutMs}ms for a post-reset frame`);
715
715
  } catch (resetError) {
@@ -719,9 +719,9 @@ var __webpack_modules__ = {
719
719
  }
720
720
  }
721
721
  }
722
- createVideoResetFrameTimeoutError() {
722
+ createVideoResetFrameTimeoutError(videoReset) {
723
723
  const timeoutMs = this.options.videoResetFrameTimeoutMs;
724
- const dataPacketsSeen = this.videoResetState?.dataPacketsSeen ?? 0;
724
+ const dataPacketsSeen = videoReset.dataPacketsSeen;
725
725
  const observation = 0 === dataPacketsSeen ? 'no data packets were observed while reset recovery was active' : `${dataPacketsSeen} data packet${1 === dataPacketsSeen ? ' was' : 's were'} observed while reset recovery was active`;
726
726
  const message = `Scrcpy video reset produced no usable fresh keyframe within the ${timeoutMs}ms post-reset window; ${observation}`;
727
727
  debugScrcpy(message);
@@ -2487,6 +2487,15 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
2487
2487
  };
2488
2488
  }
2489
2489
  calculateScrollEndPoint(start, deltaX, deltaY, maxWidth, maxHeight) {
2490
+ if (![
2491
+ start.x,
2492
+ start.y,
2493
+ deltaX,
2494
+ deltaY,
2495
+ maxWidth,
2496
+ maxHeight
2497
+ ].every(Number.isFinite) || start.x < 0 || start.x > maxWidth || start.y < 0 || start.y > maxHeight) throw new Error('Scroll origin and distance must be finite and inside the viewport');
2498
+ if (0 === deltaX && 0 === deltaY) throw new Error('Scroll distance is too small to move after rounding');
2490
2499
  const minScrollDistance = 50;
2491
2500
  let actualScrollDistanceX = 0;
2492
2501
  let actualScrollDistanceY = 0;
@@ -2504,6 +2513,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
2504
2513
  }
2505
2514
  const endX = Math.round(0 === deltaX ? start.x : deltaX > 0 ? Math.min(maxWidth, start.x + actualScrollDistanceX) : Math.max(0, start.x - actualScrollDistanceX));
2506
2515
  const endY = Math.round(0 === deltaY ? start.y : deltaY > 0 ? Math.min(maxHeight, start.y + actualScrollDistanceY) : Math.max(0, start.y - actualScrollDistanceY));
2516
+ if (0 !== deltaX && (endX - start.x) * deltaX <= 0 || 0 !== deltaY && (endY - start.y) * deltaY <= 0) throw new Error('No space to scroll from the located point; choose a point farther from the screen edge');
2507
2517
  return {
2508
2518
  x: endX,
2509
2519
  y: endY
@@ -2774,7 +2784,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
2774
2784
  }
2775
2785
  async scrollUpRaw(distance, startPoint) {
2776
2786
  if (void 0 === distance && !startPoint) return this.scrollDefault('up');
2777
- const { height } = await this.size();
2787
+ const { width, height } = await this.size();
2778
2788
  const scrollDistance = Math.round(distance || height);
2779
2789
  const hasExplicitDistance = void 0 !== distance;
2780
2790
  if (startPoint) {
@@ -2782,7 +2792,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
2782
2792
  x: Math.round(startPoint.left),
2783
2793
  y: Math.round(startPoint.top)
2784
2794
  };
2785
- const end = this.calculateScrollEndPoint(start, 0, scrollDistance, 0, height);
2795
+ const end = this.calculateScrollEndPoint(start, 0, scrollDistance, width, height);
2786
2796
  if (hasExplicitDistance) this.warnScrollDistanceClamped('up', scrollDistance, Math.abs(end.y - start.y));
2787
2797
  await this.dragPoint(start, end);
2788
2798
  return;
@@ -2794,7 +2804,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
2794
2804
  }
2795
2805
  async scrollDownRaw(distance, startPoint) {
2796
2806
  if (void 0 === distance && !startPoint) return this.scrollDefault('down');
2797
- const { height } = await this.size();
2807
+ const { width, height } = await this.size();
2798
2808
  const scrollDistance = Math.round(distance || height);
2799
2809
  const hasExplicitDistance = void 0 !== distance;
2800
2810
  if (startPoint) {
@@ -2802,7 +2812,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
2802
2812
  x: Math.round(startPoint.left),
2803
2813
  y: Math.round(startPoint.top)
2804
2814
  };
2805
- const end = this.calculateScrollEndPoint(start, 0, -scrollDistance, 0, height);
2815
+ const end = this.calculateScrollEndPoint(start, 0, -scrollDistance, width, height);
2806
2816
  if (hasExplicitDistance) this.warnScrollDistanceClamped('down', scrollDistance, Math.abs(end.y - start.y));
2807
2817
  await this.dragPoint(start, end);
2808
2818
  return;
@@ -2814,7 +2824,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
2814
2824
  }
2815
2825
  async scrollLeftRaw(distance, startPoint) {
2816
2826
  if (void 0 === distance && !startPoint) return this.scrollDefault('left');
2817
- const { width } = await this.size();
2827
+ const { width, height } = await this.size();
2818
2828
  const scrollDistance = Math.round(distance || width);
2819
2829
  const hasExplicitDistance = void 0 !== distance;
2820
2830
  if (startPoint) {
@@ -2822,7 +2832,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
2822
2832
  x: Math.round(startPoint.left),
2823
2833
  y: Math.round(startPoint.top)
2824
2834
  };
2825
- const end = this.calculateScrollEndPoint(start, scrollDistance, 0, width, 0);
2835
+ const end = this.calculateScrollEndPoint(start, scrollDistance, 0, width, height);
2826
2836
  if (hasExplicitDistance) this.warnScrollDistanceClamped('left', scrollDistance, Math.abs(end.x - start.x));
2827
2837
  await this.dragPoint(start, end);
2828
2838
  return;
@@ -2834,7 +2844,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
2834
2844
  }
2835
2845
  async scrollRightRaw(distance, startPoint) {
2836
2846
  if (void 0 === distance && !startPoint) return this.scrollDefault('right');
2837
- const { width } = await this.size();
2847
+ const { width, height } = await this.size();
2838
2848
  const scrollDistance = Math.round(distance || width);
2839
2849
  const hasExplicitDistance = void 0 !== distance;
2840
2850
  if (startPoint) {
@@ -2842,7 +2852,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
2842
2852
  x: Math.round(startPoint.left),
2843
2853
  y: Math.round(startPoint.top)
2844
2854
  };
2845
- const end = this.calculateScrollEndPoint(start, -scrollDistance, 0, width, 0);
2855
+ const end = this.calculateScrollEndPoint(start, -scrollDistance, 0, width, height);
2846
2856
  if (hasExplicitDistance) this.warnScrollDistanceClamped('right', scrollDistance, Math.abs(end.x - start.x));
2847
2857
  await this.dragPoint(start, end);
2848
2858
  return;
@@ -3573,7 +3583,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
3573
3583
  const tools = new AndroidMidsceneTools();
3574
3584
  (0, cli_namespaceObject.runToolsCLI)(tools, 'midscene-android', {
3575
3585
  stripPrefix: 'android_',
3576
- version: "1.17.8-beta-20261106101231.0",
3586
+ version: "1.17.8",
3577
3587
  extraCommands: (0, core_namespaceObject.createReportCliCommands)()
3578
3588
  }).catch((e)=>{
3579
3589
  process.exit((0, cli_namespaceObject.reportCLIError)(e));
package/dist/lib/index.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  const __rslib_import_meta_url__ = /*#__PURE__*/ function() {
3
- return 'undefined' == typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
3
+ return "u" < typeof document ? new (require('url'.replace('', ''))).URL('file:' + __filename).href : document.currentScript && document.currentScript.src || new URL('main.js', document.baseURI).href;
4
4
  }();
5
5
  var __webpack_modules__ = {
6
6
  "./src/resource-path.ts" (__unused_rspack_module, __webpack_exports__, __webpack_require__) {
@@ -553,7 +553,7 @@ var __webpack_modules__ = {
553
553
  const activeReset = this.videoResetState;
554
554
  if (activeReset) {
555
555
  if (activeReset.writePromise) await this.waitForVideoResetWrite(activeReset.writePromise, deadlineAt);
556
- return;
556
+ return activeReset;
557
557
  }
558
558
  const controller = this.scrcpyClient?.controller;
559
559
  if (!controller?.resetVideo) throw new Error('Scrcpy control channel is unavailable for video reset');
@@ -583,6 +583,7 @@ var __webpack_modules__ = {
583
583
  resetState.writePromise = resetPromise;
584
584
  resetPromise.catch(()=>{});
585
585
  await this.waitForVideoResetWrite(resetPromise, deadlineAt);
586
+ return resetState;
586
587
  }
587
588
  async waitForVideoResetWrite(writePromise, deadlineAt) {
588
589
  const remainingMs = deadlineAt - Date.now();
@@ -643,8 +644,7 @@ var __webpack_modules__ = {
643
644
  }
644
645
  async isPlanningCandidateFreshEnough(candidate) {
645
646
  if (void 0 === candidate.ptsUs) throw new Error('Scrcpy frame has no PTS metadata; cannot prove planning freshness');
646
- const ageEvaluatedAtUs = this.monotonicTimeUs();
647
- let age = this.estimateFrameAge(candidate.ptsUs, ageEvaluatedAtUs);
647
+ let age = this.estimateFrameAge(candidate.ptsUs, this.monotonicTimeUs());
648
648
  if (null === age) throw new Error('Scrcpy frame clock is not calibrated; cannot prove planning freshness');
649
649
  if (age.upperBoundUs <= MAX_FRAME_AGE_US) return true;
650
650
  const uncertaintyOnlyExceededLimit = age.estimatedAgeUs <= MAX_FRAME_AGE_US && age.upperBoundUs > MAX_FRAME_AGE_US;
@@ -658,8 +658,9 @@ var __webpack_modules__ = {
658
658
  debugScrcpy(`Unable to recalibrate scrcpy frame clock after an uncertainty-only freshness result: ${error}`);
659
659
  }
660
660
  if (void 0 !== candidate.streamEpoch && candidate.streamEpoch !== this.streamEpoch) throw new Error('Scrcpy stream epoch changed while recalibrating planning frame freshness');
661
- const recalibratedAge = this.estimateFrameAge(candidate.ptsUs, ageEvaluatedAtUs);
662
- if (recalibratedAge) age = recalibratedAge;
661
+ const recalibratedAge = this.estimateFrameAge(candidate.ptsUs, this.monotonicTimeUs());
662
+ if (!recalibratedAge) throw new Error('Scrcpy frame clock is not calibrated; cannot prove planning freshness');
663
+ age = recalibratedAge;
663
664
  if (age.upperBoundUs <= MAX_FRAME_AGE_US) {
664
665
  debugScrcpy(`Planning candidate PTS ${candidate.ptsUs}µs accepted after clock recalibration (estimated=${Number(age.estimatedAgeUs) / 1000}ms, uncertainty<=${Number(age.calibrationUncertaintyUs) / 1000}ms)`);
665
666
  return true;
@@ -676,7 +677,7 @@ var __webpack_modules__ = {
676
677
  async waitForPlanningFrame() {
677
678
  let planningBarrierArmed = false;
678
679
  let videoResetAttempted = false;
679
- let videoResetWritten = false;
680
+ let videoReset = null;
680
681
  const planningStartedAt = Date.now();
681
682
  const startupWindowRemainingMs = this.streamStartupWindow ? this.streamStartupWindow.deadlineAt - planningStartedAt : 0;
682
683
  if (this.streamStartupWindow && startupWindowRemainingMs <= 0) this.streamStartupWindow = null;
@@ -694,7 +695,7 @@ var __webpack_modules__ = {
694
695
  }
695
696
  const remainingMs = deadline - Date.now();
696
697
  if (remainingMs <= 0) {
697
- if (videoResetWritten) throw this.createVideoResetFrameTimeoutError();
698
+ if (videoReset) throw this.createVideoResetFrameTimeoutError(videoReset);
698
699
  throw new Error(`No scrcpy frame crossed the active freshness target within ${FRESH_FRAME_TIMEOUT_MS}ms`);
699
700
  }
700
701
  const shouldTryVideoReset = !videoResetAttempted && this.hasEstablishedVideoFrame && null === this.streamStartupWindow && Boolean(this.scrcpyClient?.controller?.resetVideo) && remainingMs > VIDEO_RESET_DELAY_MS;
@@ -703,13 +704,12 @@ var __webpack_modules__ = {
703
704
  candidate = await this.waitForNextKeyframe(nextFrameWaitMs);
704
705
  } catch (error) {
705
706
  if (!shouldTryVideoReset) {
706
- if (videoResetWritten) throw this.createVideoResetFrameTimeoutError();
707
+ if (videoReset) throw this.createVideoResetFrameTimeoutError(videoReset);
707
708
  throw error;
708
709
  }
709
710
  videoResetAttempted = true;
710
711
  try {
711
- await this.requestVideoReset(deadline);
712
- videoResetWritten = true;
712
+ videoReset = await this.requestVideoReset(deadline);
713
713
  deadline = Date.now() + this.options.videoResetFrameTimeoutMs;
714
714
  debugScrcpy(`Scrcpy video reset control write completed; waiting up to ${this.options.videoResetFrameTimeoutMs}ms for a post-reset frame`);
715
715
  } catch (resetError) {
@@ -719,9 +719,9 @@ var __webpack_modules__ = {
719
719
  }
720
720
  }
721
721
  }
722
- createVideoResetFrameTimeoutError() {
722
+ createVideoResetFrameTimeoutError(videoReset) {
723
723
  const timeoutMs = this.options.videoResetFrameTimeoutMs;
724
- const dataPacketsSeen = this.videoResetState?.dataPacketsSeen ?? 0;
724
+ const dataPacketsSeen = videoReset.dataPacketsSeen;
725
725
  const observation = 0 === dataPacketsSeen ? 'no data packets were observed while reset recovery was active' : `${dataPacketsSeen} data packet${1 === dataPacketsSeen ? ' was' : 's were'} observed while reset recovery was active`;
726
726
  const message = `Scrcpy video reset produced no usable fresh keyframe within the ${timeoutMs}ms post-reset window; ${observation}`;
727
727
  debugScrcpy(message);
@@ -1178,7 +1178,7 @@ function __webpack_require__(moduleId) {
1178
1178
  })();
1179
1179
  (()=>{
1180
1180
  __webpack_require__.r = (exports1)=>{
1181
- if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
1181
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
1182
1182
  value: 'Module'
1183
1183
  });
1184
1184
  Object.defineProperty(exports1, '__esModule', {
@@ -2418,6 +2418,15 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
2418
2418
  };
2419
2419
  }
2420
2420
  calculateScrollEndPoint(start, deltaX, deltaY, maxWidth, maxHeight) {
2421
+ if (![
2422
+ start.x,
2423
+ start.y,
2424
+ deltaX,
2425
+ deltaY,
2426
+ maxWidth,
2427
+ maxHeight
2428
+ ].every(Number.isFinite) || start.x < 0 || start.x > maxWidth || start.y < 0 || start.y > maxHeight) throw new Error('Scroll origin and distance must be finite and inside the viewport');
2429
+ if (0 === deltaX && 0 === deltaY) throw new Error('Scroll distance is too small to move after rounding');
2421
2430
  const minScrollDistance = 50;
2422
2431
  let actualScrollDistanceX = 0;
2423
2432
  let actualScrollDistanceY = 0;
@@ -2435,6 +2444,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
2435
2444
  }
2436
2445
  const endX = Math.round(0 === deltaX ? start.x : deltaX > 0 ? Math.min(maxWidth, start.x + actualScrollDistanceX) : Math.max(0, start.x - actualScrollDistanceX));
2437
2446
  const endY = Math.round(0 === deltaY ? start.y : deltaY > 0 ? Math.min(maxHeight, start.y + actualScrollDistanceY) : Math.max(0, start.y - actualScrollDistanceY));
2447
+ if (0 !== deltaX && (endX - start.x) * deltaX <= 0 || 0 !== deltaY && (endY - start.y) * deltaY <= 0) throw new Error('No space to scroll from the located point; choose a point farther from the screen edge');
2438
2448
  return {
2439
2449
  x: endX,
2440
2450
  y: endY
@@ -2705,7 +2715,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
2705
2715
  }
2706
2716
  async scrollUpRaw(distance, startPoint) {
2707
2717
  if (void 0 === distance && !startPoint) return this.scrollDefault('up');
2708
- const { height } = await this.size();
2718
+ const { width, height } = await this.size();
2709
2719
  const scrollDistance = Math.round(distance || height);
2710
2720
  const hasExplicitDistance = void 0 !== distance;
2711
2721
  if (startPoint) {
@@ -2713,7 +2723,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
2713
2723
  x: Math.round(startPoint.left),
2714
2724
  y: Math.round(startPoint.top)
2715
2725
  };
2716
- const end = this.calculateScrollEndPoint(start, 0, scrollDistance, 0, height);
2726
+ const end = this.calculateScrollEndPoint(start, 0, scrollDistance, width, height);
2717
2727
  if (hasExplicitDistance) this.warnScrollDistanceClamped('up', scrollDistance, Math.abs(end.y - start.y));
2718
2728
  await this.dragPoint(start, end);
2719
2729
  return;
@@ -2725,7 +2735,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
2725
2735
  }
2726
2736
  async scrollDownRaw(distance, startPoint) {
2727
2737
  if (void 0 === distance && !startPoint) return this.scrollDefault('down');
2728
- const { height } = await this.size();
2738
+ const { width, height } = await this.size();
2729
2739
  const scrollDistance = Math.round(distance || height);
2730
2740
  const hasExplicitDistance = void 0 !== distance;
2731
2741
  if (startPoint) {
@@ -2733,7 +2743,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
2733
2743
  x: Math.round(startPoint.left),
2734
2744
  y: Math.round(startPoint.top)
2735
2745
  };
2736
- const end = this.calculateScrollEndPoint(start, 0, -scrollDistance, 0, height);
2746
+ const end = this.calculateScrollEndPoint(start, 0, -scrollDistance, width, height);
2737
2747
  if (hasExplicitDistance) this.warnScrollDistanceClamped('down', scrollDistance, Math.abs(end.y - start.y));
2738
2748
  await this.dragPoint(start, end);
2739
2749
  return;
@@ -2745,7 +2755,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
2745
2755
  }
2746
2756
  async scrollLeftRaw(distance, startPoint) {
2747
2757
  if (void 0 === distance && !startPoint) return this.scrollDefault('left');
2748
- const { width } = await this.size();
2758
+ const { width, height } = await this.size();
2749
2759
  const scrollDistance = Math.round(distance || width);
2750
2760
  const hasExplicitDistance = void 0 !== distance;
2751
2761
  if (startPoint) {
@@ -2753,7 +2763,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
2753
2763
  x: Math.round(startPoint.left),
2754
2764
  y: Math.round(startPoint.top)
2755
2765
  };
2756
- const end = this.calculateScrollEndPoint(start, scrollDistance, 0, width, 0);
2766
+ const end = this.calculateScrollEndPoint(start, scrollDistance, 0, width, height);
2757
2767
  if (hasExplicitDistance) this.warnScrollDistanceClamped('left', scrollDistance, Math.abs(end.x - start.x));
2758
2768
  await this.dragPoint(start, end);
2759
2769
  return;
@@ -2765,7 +2775,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
2765
2775
  }
2766
2776
  async scrollRightRaw(distance, startPoint) {
2767
2777
  if (void 0 === distance && !startPoint) return this.scrollDefault('right');
2768
- const { width } = await this.size();
2778
+ const { width, height } = await this.size();
2769
2779
  const scrollDistance = Math.round(distance || width);
2770
2780
  const hasExplicitDistance = void 0 !== distance;
2771
2781
  if (startPoint) {
@@ -2773,7 +2783,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
2773
2783
  x: Math.round(startPoint.left),
2774
2784
  y: Math.round(startPoint.top)
2775
2785
  };
2776
- const end = this.calculateScrollEndPoint(start, -scrollDistance, 0, width, 0);
2786
+ const end = this.calculateScrollEndPoint(start, -scrollDistance, 0, width, height);
2777
2787
  if (hasExplicitDistance) this.warnScrollDistanceClamped('right', scrollDistance, Math.abs(end.x - start.x));
2778
2788
  await this.dragPoint(start, end);
2779
2789
  return;
@@ -13,7 +13,7 @@ var __webpack_require__ = {};
13
13
  })();
14
14
  (()=>{
15
15
  __webpack_require__.r = (exports1)=>{
16
- if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
16
+ if ("u" > typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
17
  value: 'Module'
18
18
  });
19
19
  Object.defineProperty(exports1, '__esModule', {
@@ -672,6 +672,9 @@ declare class ScrcpyScreenshotManager {
672
672
  * Restart scrcpy's capture and encoder pipeline without rebuilding the video
673
673
  * stream or the underlying ADB transport. One request is shared by all
674
674
  * concurrent capture callers until a post-reset keyframe is accepted.
675
+ *
676
+ * Returns the reset's state, so the caller can still read its packet count
677
+ * after an accepted keyframe has ended the active reset.
675
678
  */
676
679
  private requestVideoReset;
677
680
  private waitForVideoResetWrite;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@midscene/android",
3
- "version": "1.17.8-beta-20261106101231.0",
3
+ "version": "1.17.8",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/web-infra-dev/midscene.git",
@@ -47,21 +47,21 @@
47
47
  "appium-adb": "15.0.9",
48
48
  "sharp": "^0.35.5",
49
49
  "zod": "^3.25.1",
50
- "@midscene/core": "1.17.8-beta-20261106101231.0",
51
- "@midscene/shared": "1.17.8-beta-20261106101231.0"
50
+ "@midscene/core": "1.17.8",
51
+ "@midscene/shared": "1.17.8"
52
52
  },
53
53
  "optionalDependencies": {
54
54
  "@ffmpeg-installer/ffmpeg": "^1.1.0"
55
55
  },
56
56
  "devDependencies": {
57
- "@rslib/core": "^0.18.3",
57
+ "@rslib/core": "~0.19.6",
58
58
  "@rstest/core": "0.12.0",
59
59
  "@types/node": "^18.0.0",
60
60
  "dotenv": "^16.4.5",
61
- "tsx": "^4.19.2",
61
+ "tsx": "^4.23.15",
62
62
  "typescript": "^5.8.3",
63
63
  "undici": "^7.30.1",
64
- "@midscene/playground": "1.17.8-beta-20261106101231.0"
64
+ "@midscene/playground": "1.17.8"
65
65
  },
66
66
  "license": "MIT",
67
67
  "scripts": {