From 93961b11ad0957622ace27ec14e87f191fccc1a4 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Sun, 15 Mar 2026 16:24:11 +0100 Subject: [PATCH 1/2] fix: Add exponential backoff interval on consecutive screenshot failures --- WebDriverAgentLib/Utilities/FBMjpegServer.m | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/WebDriverAgentLib/Utilities/FBMjpegServer.m b/WebDriverAgentLib/Utilities/FBMjpegServer.m index 4c786ba03..4f061d2e3 100644 --- a/WebDriverAgentLib/Utilities/FBMjpegServer.m +++ b/WebDriverAgentLib/Utilities/FBMjpegServer.m @@ -21,6 +21,8 @@ static const NSUInteger MAX_FPS = 60; static const NSTimeInterval FRAME_TIMEOUT = 1.; +static const NSTimeInterval FAILURE_BACKOFF_MIN = 1.0; +static const NSTimeInterval FAILURE_BACKOFF_MAX = 10.0; static NSString *const SERVER_NAME = @"WDA MJPEG Server"; static const char *QUEUE_NAME = "JPEG Screenshots Provider Queue"; @@ -32,6 +34,7 @@ @interface FBMjpegServer() @property (nonatomic, readonly) NSMutableArray *listeningClients; @property (nonatomic, readonly) FBImageProcessor *imageProcessor; @property (nonatomic, readonly) long long mainScreenID; +@property (nonatomic, assign) NSUInteger consecutiveScreenshotFailures; @end @@ -41,6 +44,7 @@ @implementation FBMjpegServer - (instancetype)init { if ((self = [super init])) { + _consecutiveScreenshotFailures = 0; _listeningClients = [NSMutableArray array]; dispatch_queue_attr_t queueAttributes = dispatch_queue_attr_make_with_qos_class(DISPATCH_QUEUE_SERIAL, QOS_CLASS_UTILITY, 0); _backgroundQueue = dispatch_queue_create(QUEUE_NAME, queueAttributes); @@ -91,10 +95,16 @@ - (void)streamScreenshot error:&error]; if (nil == screenshotData) { [FBLogger logFmt:@"%@", error.description]; - [self scheduleNextScreenshotWithInterval:timerInterval timeStarted:timeStarted]; + self.consecutiveScreenshotFailures++; + NSTimeInterval backoffSeconds = MIN(FAILURE_BACKOFF_MAX, + FAILURE_BACKOFF_MIN * (1 << MIN(self.consecutiveScreenshotFailures, 4))); + uint64_t backoffInterval = (uint64_t)(backoffSeconds * NSEC_PER_SEC); + [self scheduleNextScreenshotWithInterval:backoffInterval timeStarted:timeStarted]; return; } + self.consecutiveScreenshotFailures = 0; + CGFloat scalingFactor = FBConfiguration.mjpegScalingFactor / 100.0; [self.imageProcessor submitImageData:screenshotData scalingFactor:scalingFactor From 725f35cd27d7d0aba2399239fc98e474cb77fa66 Mon Sep 17 00:00:00 2001 From: Mykola Mokhnach Date: Sun, 15 Mar 2026 16:28:47 +0100 Subject: [PATCH 2/2] fix build --- lib/webdriveragent.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/webdriveragent.ts b/lib/webdriveragent.ts index 954a15362..95daacf4b 100644 --- a/lib/webdriveragent.ts +++ b/lib/webdriveragent.ts @@ -315,11 +315,13 @@ export class WebDriverAgent { private async parseBundleId(wdaBundlePath: string): Promise { const infoPlistPath = path.join(wdaBundlePath, 'Info.plist'); - const infoPlist = await plist.parsePlist(await fs.readFile(infoPlistPath)); + const infoPlist = (await plist.parsePlist(await fs.readFile(infoPlistPath))) as { + CFBundleIdentifier?: string; + }; if (!infoPlist.CFBundleIdentifier) { throw new Error(`Could not find bundle id in '${infoPlistPath}'`); } - return infoPlist.CFBundleIdentifier as string; + return infoPlist.CFBundleIdentifier; } private async fetchWDABundle(): Promise {