@@ -20,7 +20,10 @@ import {
20
20
import { sleep } from '@midscene/core/utils' ;
21
21
import { DEFAULT_WDA_PORT } from '@midscene/shared/constants' ;
22
22
import type { ElementInfo } from '@midscene/shared/extractor' ;
23
- import { createImgBase64ByFormat } from '@midscene/shared/img' ;
23
+ import {
24
+ createImgBase64ByFormat ,
25
+ resizeAndConvertImgBuffer ,
26
+ } from '@midscene/shared/img' ;
24
27
import { getDebug } from '@midscene/shared/logger' ;
25
28
import { WDAManager } from '@midscene/webdriver' ;
26
29
import { IOSWebDriverClient as WebDriverAgentBackend } from './ios-webdriver-client' ;
@@ -37,6 +40,7 @@ export type IOSDeviceOpt = {
37
40
wdaPort ?: number ;
38
41
wdaHost ?: string ;
39
42
useWDA ?: boolean ;
43
+ screenshotResizeRatio ?: number ;
40
44
} & IOSDeviceInputOpt ;
41
45
42
46
export class IOSDevice implements AbstractInterface {
@@ -353,7 +357,36 @@ ScreenSize: ${size.width}x${size.height} (DPR: ${size.scale})
353
357
async screenshotBase64 ( ) : Promise < string > {
354
358
debugDevice ( 'Taking screenshot via WDA' ) ;
355
359
try {
360
+ const { width, height } = await this . size ( ) ;
356
361
const base64Data = await this . wdaBackend . takeScreenshot ( ) ;
362
+
363
+ // Apply custom resize ratio if specified
364
+ const resizeRatio = this . options ?. screenshotResizeRatio ?? 1.0 ;
365
+
366
+ if ( resizeRatio !== 1.0 ) {
367
+ debugDevice ( `Applying custom resize ratio: ${ resizeRatio } ` ) ;
368
+ const targetWidth = Math . round ( width * resizeRatio ) ;
369
+ const targetHeight = Math . round ( height * resizeRatio ) ;
370
+ debugDevice ( `Target size: ${ targetWidth } x${ targetHeight } ` ) ;
371
+
372
+ const screenshotBuffer = Buffer . from ( base64Data , 'base64' ) ;
373
+ const { buffer, format } = await resizeAndConvertImgBuffer (
374
+ 'png' ,
375
+ screenshotBuffer ,
376
+ {
377
+ width : targetWidth ,
378
+ height : targetHeight ,
379
+ } ,
380
+ ) ;
381
+
382
+ const result = createImgBase64ByFormat (
383
+ format ,
384
+ buffer . toString ( 'base64' ) ,
385
+ ) ;
386
+ debugDevice ( 'Screenshot taken and resized successfully' ) ;
387
+ return result ;
388
+ }
389
+
357
390
const result = createImgBase64ByFormat ( 'png' , base64Data ) ;
358
391
debugDevice ( 'Screenshot taken successfully' ) ;
359
392
return result ;
0 commit comments