@midscene/android 1.17.8-beta-20261110095715.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.
package/dist/es/430.mjs CHANGED
@@ -615,7 +615,7 @@ class ScrcpyScreenshotManager {
615
615
  const activeReset = this.videoResetState;
616
616
  if (activeReset) {
617
617
  if (activeReset.writePromise) await this.waitForVideoResetWrite(activeReset.writePromise, deadlineAt);
618
- return;
618
+ return activeReset;
619
619
  }
620
620
  const controller = this.scrcpyClient?.controller;
621
621
  if (!controller?.resetVideo) throw new Error('Scrcpy control channel is unavailable for video reset');
@@ -645,6 +645,7 @@ class ScrcpyScreenshotManager {
645
645
  resetState.writePromise = resetPromise;
646
646
  resetPromise.catch(()=>{});
647
647
  await this.waitForVideoResetWrite(resetPromise, deadlineAt);
648
+ return resetState;
648
649
  }
649
650
  async waitForVideoResetWrite(writePromise, deadlineAt) {
650
651
  const remainingMs = deadlineAt - Date.now();
@@ -705,8 +706,7 @@ class ScrcpyScreenshotManager {
705
706
  }
706
707
  async isPlanningCandidateFreshEnough(candidate) {
707
708
  if (void 0 === candidate.ptsUs) throw new Error('Scrcpy frame has no PTS metadata; cannot prove planning freshness');
708
- const ageEvaluatedAtUs = this.monotonicTimeUs();
709
- let age = this.estimateFrameAge(candidate.ptsUs, ageEvaluatedAtUs);
709
+ let age = this.estimateFrameAge(candidate.ptsUs, this.monotonicTimeUs());
710
710
  if (null === age) throw new Error('Scrcpy frame clock is not calibrated; cannot prove planning freshness');
711
711
  if (age.upperBoundUs <= MAX_FRAME_AGE_US) return true;
712
712
  const uncertaintyOnlyExceededLimit = age.estimatedAgeUs <= MAX_FRAME_AGE_US && age.upperBoundUs > MAX_FRAME_AGE_US;
@@ -720,8 +720,9 @@ class ScrcpyScreenshotManager {
720
720
  debugScrcpy(`Unable to recalibrate scrcpy frame clock after an uncertainty-only freshness result: ${error}`);
721
721
  }
722
722
  if (void 0 !== candidate.streamEpoch && candidate.streamEpoch !== this.streamEpoch) throw new Error('Scrcpy stream epoch changed while recalibrating planning frame freshness');
723
- const recalibratedAge = this.estimateFrameAge(candidate.ptsUs, ageEvaluatedAtUs);
724
- if (recalibratedAge) age = recalibratedAge;
723
+ const recalibratedAge = this.estimateFrameAge(candidate.ptsUs, this.monotonicTimeUs());
724
+ if (!recalibratedAge) throw new Error('Scrcpy frame clock is not calibrated; cannot prove planning freshness');
725
+ age = recalibratedAge;
725
726
  if (age.upperBoundUs <= MAX_FRAME_AGE_US) {
726
727
  debugScrcpy(`Planning candidate PTS ${candidate.ptsUs}µs accepted after clock recalibration (estimated=${Number(age.estimatedAgeUs) / 1000}ms, uncertainty<=${Number(age.calibrationUncertaintyUs) / 1000}ms)`);
727
728
  return true;
@@ -738,7 +739,7 @@ class ScrcpyScreenshotManager {
738
739
  async waitForPlanningFrame() {
739
740
  let planningBarrierArmed = false;
740
741
  let videoResetAttempted = false;
741
- let videoResetWritten = false;
742
+ let videoReset = null;
742
743
  const planningStartedAt = Date.now();
743
744
  const startupWindowRemainingMs = this.streamStartupWindow ? this.streamStartupWindow.deadlineAt - planningStartedAt : 0;
744
745
  if (this.streamStartupWindow && startupWindowRemainingMs <= 0) this.streamStartupWindow = null;
@@ -756,7 +757,7 @@ class ScrcpyScreenshotManager {
756
757
  }
757
758
  const remainingMs = deadline - Date.now();
758
759
  if (remainingMs <= 0) {
759
- if (videoResetWritten) throw this.createVideoResetFrameTimeoutError();
760
+ if (videoReset) throw this.createVideoResetFrameTimeoutError(videoReset);
760
761
  throw new Error(`No scrcpy frame crossed the active freshness target within ${FRESH_FRAME_TIMEOUT_MS}ms`);
761
762
  }
762
763
  const shouldTryVideoReset = !videoResetAttempted && this.hasEstablishedVideoFrame && null === this.streamStartupWindow && Boolean(this.scrcpyClient?.controller?.resetVideo) && remainingMs > VIDEO_RESET_DELAY_MS;
@@ -765,13 +766,12 @@ class ScrcpyScreenshotManager {
765
766
  candidate = await this.waitForNextKeyframe(nextFrameWaitMs);
766
767
  } catch (error) {
767
768
  if (!shouldTryVideoReset) {
768
- if (videoResetWritten) throw this.createVideoResetFrameTimeoutError();
769
+ if (videoReset) throw this.createVideoResetFrameTimeoutError(videoReset);
769
770
  throw error;
770
771
  }
771
772
  videoResetAttempted = true;
772
773
  try {
773
- await this.requestVideoReset(deadline);
774
- videoResetWritten = true;
774
+ videoReset = await this.requestVideoReset(deadline);
775
775
  deadline = Date.now() + this.options.videoResetFrameTimeoutMs;
776
776
  debugScrcpy(`Scrcpy video reset control write completed; waiting up to ${this.options.videoResetFrameTimeoutMs}ms for a post-reset frame`);
777
777
  } catch (resetError) {
@@ -781,9 +781,9 @@ class ScrcpyScreenshotManager {
781
781
  }
782
782
  }
783
783
  }
784
- createVideoResetFrameTimeoutError() {
784
+ createVideoResetFrameTimeoutError(videoReset) {
785
785
  const timeoutMs = this.options.videoResetFrameTimeoutMs;
786
- const dataPacketsSeen = this.videoResetState?.dataPacketsSeen ?? 0;
786
+ const dataPacketsSeen = videoReset.dataPacketsSeen;
787
787
  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`;
788
788
  const message = `Scrcpy video reset produced no usable fresh keyframe within the ${timeoutMs}ms post-reset window; ${observation}`;
789
789
  debugScrcpy(message);
@@ -2207,6 +2207,15 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
2207
2207
  };
2208
2208
  }
2209
2209
  calculateScrollEndPoint(start, deltaX, deltaY, maxWidth, maxHeight) {
2210
+ if (![
2211
+ start.x,
2212
+ start.y,
2213
+ deltaX,
2214
+ deltaY,
2215
+ maxWidth,
2216
+ maxHeight
2217
+ ].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');
2218
+ if (0 === deltaX && 0 === deltaY) throw new Error('Scroll distance is too small to move after rounding');
2210
2219
  const minScrollDistance = 50;
2211
2220
  let actualScrollDistanceX = 0;
2212
2221
  let actualScrollDistanceY = 0;
@@ -2224,6 +2233,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
2224
2233
  }
2225
2234
  const endX = Math.round(0 === deltaX ? start.x : deltaX > 0 ? Math.min(maxWidth, start.x + actualScrollDistanceX) : Math.max(0, start.x - actualScrollDistanceX));
2226
2235
  const endY = Math.round(0 === deltaY ? start.y : deltaY > 0 ? Math.min(maxHeight, start.y + actualScrollDistanceY) : Math.max(0, start.y - actualScrollDistanceY));
2236
+ 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');
2227
2237
  return {
2228
2238
  x: endX,
2229
2239
  y: endY
@@ -2494,7 +2504,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
2494
2504
  }
2495
2505
  async scrollUpRaw(distance, startPoint) {
2496
2506
  if (void 0 === distance && !startPoint) return this.scrollDefault('up');
2497
- const { height } = await this.size();
2507
+ const { width, height } = await this.size();
2498
2508
  const scrollDistance = Math.round(distance || height);
2499
2509
  const hasExplicitDistance = void 0 !== distance;
2500
2510
  if (startPoint) {
@@ -2502,7 +2512,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
2502
2512
  x: Math.round(startPoint.left),
2503
2513
  y: Math.round(startPoint.top)
2504
2514
  };
2505
- const end = this.calculateScrollEndPoint(start, 0, scrollDistance, 0, height);
2515
+ const end = this.calculateScrollEndPoint(start, 0, scrollDistance, width, height);
2506
2516
  if (hasExplicitDistance) this.warnScrollDistanceClamped('up', scrollDistance, Math.abs(end.y - start.y));
2507
2517
  await this.dragPoint(start, end);
2508
2518
  return;
@@ -2514,7 +2524,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
2514
2524
  }
2515
2525
  async scrollDownRaw(distance, startPoint) {
2516
2526
  if (void 0 === distance && !startPoint) return this.scrollDefault('down');
2517
- const { height } = await this.size();
2527
+ const { width, height } = await this.size();
2518
2528
  const scrollDistance = Math.round(distance || height);
2519
2529
  const hasExplicitDistance = void 0 !== distance;
2520
2530
  if (startPoint) {
@@ -2522,7 +2532,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
2522
2532
  x: Math.round(startPoint.left),
2523
2533
  y: Math.round(startPoint.top)
2524
2534
  };
2525
- const end = this.calculateScrollEndPoint(start, 0, -scrollDistance, 0, height);
2535
+ const end = this.calculateScrollEndPoint(start, 0, -scrollDistance, width, height);
2526
2536
  if (hasExplicitDistance) this.warnScrollDistanceClamped('down', scrollDistance, Math.abs(end.y - start.y));
2527
2537
  await this.dragPoint(start, end);
2528
2538
  return;
@@ -2534,7 +2544,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
2534
2544
  }
2535
2545
  async scrollLeftRaw(distance, startPoint) {
2536
2546
  if (void 0 === distance && !startPoint) return this.scrollDefault('left');
2537
- const { width } = await this.size();
2547
+ const { width, height } = await this.size();
2538
2548
  const scrollDistance = Math.round(distance || width);
2539
2549
  const hasExplicitDistance = void 0 !== distance;
2540
2550
  if (startPoint) {
@@ -2542,7 +2552,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
2542
2552
  x: Math.round(startPoint.left),
2543
2553
  y: Math.round(startPoint.top)
2544
2554
  };
2545
- const end = this.calculateScrollEndPoint(start, scrollDistance, 0, width, 0);
2555
+ const end = this.calculateScrollEndPoint(start, scrollDistance, 0, width, height);
2546
2556
  if (hasExplicitDistance) this.warnScrollDistanceClamped('left', scrollDistance, Math.abs(end.x - start.x));
2547
2557
  await this.dragPoint(start, end);
2548
2558
  return;
@@ -2554,7 +2564,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
2554
2564
  }
2555
2565
  async scrollRightRaw(distance, startPoint) {
2556
2566
  if (void 0 === distance && !startPoint) return this.scrollDefault('right');
2557
- const { width } = await this.size();
2567
+ const { width, height } = await this.size();
2558
2568
  const scrollDistance = Math.round(distance || width);
2559
2569
  const hasExplicitDistance = void 0 !== distance;
2560
2570
  if (startPoint) {
@@ -2562,7 +2572,7 @@ ${Object.keys(size).filter((key)=>size[key]).map((key)=>` ${key} size: ${size[k
2562
2572
  x: Math.round(startPoint.left),
2563
2573
  y: Math.round(startPoint.top)
2564
2574
  };
2565
- const end = this.calculateScrollEndPoint(start, -scrollDistance, 0, width, 0);
2575
+ const end = this.calculateScrollEndPoint(start, -scrollDistance, 0, width, height);
2566
2576
  if (hasExplicitDistance) this.warnScrollDistanceClamped('right', scrollDistance, Math.abs(end.x - start.x));
2567
2577
  await this.dragPoint(start, end);
2568
2578
  return;
package/dist/es/cli.mjs CHANGED
@@ -3,7 +3,7 @@ import { AndroidMidsceneTools, createReportCliCommands } from "./430.mjs";
3
3
  const tools = new AndroidMidsceneTools();
4
4
  runToolsCLI(tools, 'midscene-android', {
5
5
  stripPrefix: 'android_',
6
- version: "1.17.8-beta-20261110095715.0",
6
+ version: "1.17.8",
7
7
  extraCommands: createReportCliCommands()
8
8
  }).catch((e)=>{
9
9
  process.exit(reportCLIError(e));
package/dist/lib/cli.js CHANGED
@@ -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-20261110095715.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
@@ -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);
@@ -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;
@@ -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-20261110095715.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,8 +47,8 @@
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-20261110095715.0",
51
- "@midscene/shared": "1.17.8-beta-20261110095715.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"
@@ -61,7 +61,7 @@
61
61
  "tsx": "^4.23.15",
62
62
  "typescript": "^5.8.3",
63
63
  "undici": "^7.30.1",
64
- "@midscene/playground": "1.17.8-beta-20261110095715.0"
64
+ "@midscene/playground": "1.17.8"
65
65
  },
66
66
  "license": "MIT",
67
67
  "scripts": {