@@ -12,6 +12,7 @@ import {
1212 type PermissionSettingOptions ,
1313} from '../permission-utils.ts' ;
1414import { parseAppearanceAction } from '../appearance.ts' ;
15+ import { runIosRunnerCommand } from './runner-client.ts' ;
1516
1617import { IOS_APP_LAUNCH_TIMEOUT_MS , IOS_DEVICECTL_TIMEOUT_MS } from './config.ts' ;
1718import {
@@ -221,10 +222,33 @@ export async function screenshotIos(device: DeviceInfo, outPath: string): Promis
221222 return ;
222223 }
223224
224- await runIosDevicectl ( [ 'device' , 'screenshot' , '--device' , device . id , outPath ] , {
225- action : 'capture iOS screenshot' ,
226- deviceId : device . id ,
227- } ) ;
225+ try {
226+ await runIosDevicectl ( [ 'device' , 'screenshot' , '--device' , device . id , outPath ] , {
227+ action : 'capture iOS screenshot' ,
228+ deviceId : device . id ,
229+ } ) ;
230+ return ;
231+ } catch ( error ) {
232+ if ( ! shouldFallbackToRunnerForIosScreenshot ( error ) ) {
233+ throw error ;
234+ }
235+ }
236+
237+ await runIosRunnerCommand ( device , { command : 'screenshot' , outPath } ) ;
238+ }
239+
240+ export function shouldFallbackToRunnerForIosScreenshot ( error : unknown ) : boolean {
241+ if ( ! ( error instanceof AppError ) ) return false ;
242+ if ( error . code !== 'COMMAND_FAILED' ) return false ;
243+ const details = ( error . details ?? { } ) as { stdout ?: unknown ; stderr ?: unknown } ;
244+ const stdout = typeof details . stdout === 'string' ? details . stdout : '' ;
245+ const stderr = typeof details . stderr === 'string' ? details . stderr : '' ;
246+ const combined = `${ error . message } \n${ stdout } \n${ stderr } ` . toLowerCase ( ) ;
247+ return (
248+ combined . includes ( "unknown option '--device'" ) ||
249+ ( combined . includes ( 'unknown subcommand' ) && combined . includes ( 'screenshot' ) ) ||
250+ ( combined . includes ( 'unrecognized subcommand' ) && combined . includes ( 'screenshot' ) )
251+ ) ;
228252}
229253
230254export async function readIosClipboardText ( device : DeviceInfo ) : Promise < string > {
0 commit comments