From 7699f995fbfedb1cf2df00d981bab2be5f0fd86b Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Thu, 5 Mar 2026 22:48:08 -0800 Subject: [PATCH 01/10] feat: make maxChildren configuable --- .../XCAXClient_iOS+FBSnapshotReqParams.h | 2 ++ .../XCAXClient_iOS+FBSnapshotReqParams.m | 8 ++++++++ WebDriverAgentLib/Commands/FBSessionCommands.m | 4 ++++ WebDriverAgentLib/Utilities/FBConfiguration.h | 15 +++++++++++++++ WebDriverAgentLib/Utilities/FBConfiguration.m | 14 ++++++++++++++ WebDriverAgentLib/Utilities/FBSettings.h | 1 + WebDriverAgentLib/Utilities/FBSettings.m | 1 + 7 files changed, 45 insertions(+) diff --git a/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.h b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.h index d984e0b9e..257092419 100644 --- a/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.h +++ b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.h @@ -12,9 +12,11 @@ NS_ASSUME_NONNULL_BEGIN +extern NSString *const FBSnapshotMaxChildrenKey; extern NSString *const FBSnapshotMaxDepthKey; void FBSetCustomParameterForElementSnapshot (NSString* name, id value); +void FBRemoveCustomParameterForElementSnapshot (NSString* name); id __nullable FBGetCustomParameterForElementSnapshot (NSString *name); diff --git a/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m index 0d39ba0b2..4d571b70d 100644 --- a/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m +++ b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m @@ -19,6 +19,7 @@ @"maxDepth" : (int)2147483647 */ NSString *const FBSnapshotMaxDepthKey = @"maxDepth"; +NSString *const FBSnapshotMaxChildrenKey = @"maxChildren"; static id (*original_defaultParameters)(id, SEL); static id (*original_snapshotParameters)(id, SEL); @@ -35,6 +36,13 @@ void FBSetCustomParameterForElementSnapshot (NSString *name, id value) customRequestParameters[name] = value; } +void FBRemoveCustomParameterForElementSnapshot (NSString *name) +{ + if (customRequestParameters && [customRequestParameters objectForKey:name]) { + [customRequestParameters removeObjectForKey:name]; + } +} + id FBGetCustomParameterForElementSnapshot (NSString *name) { return customRequestParameters[name]; diff --git a/WebDriverAgentLib/Commands/FBSessionCommands.m b/WebDriverAgentLib/Commands/FBSessionCommands.m index 86535eb7f..c70465073 100644 --- a/WebDriverAgentLib/Commands/FBSessionCommands.m +++ b/WebDriverAgentLib/Commands/FBSessionCommands.m @@ -337,6 +337,7 @@ + (NSArray *)routes FB_SETTING_KEYBOARD_AUTOCORRECTION: @([FBConfiguration keyboardAutocorrection]), FB_SETTING_KEYBOARD_PREDICTION: @([FBConfiguration keyboardPrediction]), FB_SETTING_SNAPSHOT_MAX_DEPTH: @([FBConfiguration snapshotMaxDepth]), + FB_SETTING_SNAPSHOT_MAX_CHILDREN: @([FBConfiguration snapshotMaxChildren]), FB_SETTING_USE_FIRST_MATCH: @([FBConfiguration useFirstMatch]), FB_SETTING_WAIT_FOR_IDLE_TIMEOUT: @([FBConfiguration waitForIdleTimeout]), FB_SETTING_ANIMATION_COOL_OFF_TIMEOUT: @([FBConfiguration animationCoolOffTimeout]), @@ -404,6 +405,9 @@ + (NSArray *)routes if (nil != [settings objectForKey:FB_SETTING_SNAPSHOT_MAX_DEPTH]) { [FBConfiguration setSnapshotMaxDepth:[[settings objectForKey:FB_SETTING_SNAPSHOT_MAX_DEPTH] intValue]]; } + if (nil != [settings objectForKey:FB_SETTING_SNAPSHOT_MAX_CHILDREN]) { + [FBConfiguration setSnapshotMaxChildren:[[settings objectForKey:FB_SETTING_SNAPSHOT_MAX_CHILDREN] intValue]]; + } if (nil != [settings objectForKey:FB_SETTING_USE_FIRST_MATCH]) { [FBConfiguration setUseFirstMatch:[[settings objectForKey:FB_SETTING_USE_FIRST_MATCH] boolValue]]; } diff --git a/WebDriverAgentLib/Utilities/FBConfiguration.h b/WebDriverAgentLib/Utilities/FBConfiguration.h index 20aa0a9d5..7f86d035b 100644 --- a/WebDriverAgentLib/Utilities/FBConfiguration.h +++ b/WebDriverAgentLib/Utilities/FBConfiguration.h @@ -10,6 +10,7 @@ NS_ASSUME_NONNULL_BEGIN +extern NSString *const FBSnapshotMaxChildrenKey; extern NSString *const FBSnapshotMaxDepthKey; /** @@ -206,6 +207,20 @@ typedef NS_ENUM(NSInteger, FBConfigurationKeyboardPreference) { */ + (int)snapshotMaxDepth; +/** + Sets maximum element children for traversing elements tree in each snapshot while requesting XCElementSnapshot. + Used to set maxChildren value in a dictionary provided by XCAXClient_iOS's method defaultParams. + The original XCAXClient_iOS maxChildren value is set to INT_MAX. + + @param maxChildren The number of maximum element children for traversing elements tree + */ ++ (void)setSnapshotMaxChildren:(int)maxChildren; + +/** + @return The number of maximum depth for traversing elements tree + */ ++ (int)snapshotMaxChildren; + /** * Whether to use fast search result matching while searching for elements. * By default this is disabled due to https://github.com/appium/appium/issues/10101 diff --git a/WebDriverAgentLib/Utilities/FBConfiguration.m b/WebDriverAgentLib/Utilities/FBConfiguration.m index 1bae66e85..14e5a8d1f 100644 --- a/WebDriverAgentLib/Utilities/FBConfiguration.m +++ b/WebDriverAgentLib/Utilities/FBConfiguration.m @@ -6,6 +6,8 @@ * LICENSE file in the root directory of this source tree. */ +#import + #import "FBConfiguration.h" #import "AXSettings.h" @@ -385,6 +387,17 @@ + (int)snapshotMaxDepth return [FBGetCustomParameterForElementSnapshot(FBSnapshotMaxDepthKey) intValue]; } + ++ (void)setSnapshotMaxChildren:(int)maxChildren +{ + FBSetCustomParameterForElementSnapshot(FBSnapshotMaxChildrenKey, @(maxChildren)); +} + ++ (int)snapshotMaxChildren +{ + return [FBGetCustomParameterForElementSnapshot(FBSnapshotMaxChildrenKey) intValue]; +} + + (void)setShouldRespectSystemAlerts:(BOOL)value { FBShouldRespectSystemAlerts = value; @@ -541,6 +554,7 @@ + (void)resetSessionSettings FBAnimationCoolOffTimeout = 2.; // 50 should be enough for the majority of the cases. The performance is acceptable for values up to 100. FBSetCustomParameterForElementSnapshot(FBSnapshotMaxDepthKey, @50); + FBRemoveCustomParameterForElementSnapshot(FBSnapshotMaxChildrenKey); FBUseClearTextShortcut = YES; FBLimitXpathContextScope = YES; #if !TARGET_OS_TV diff --git a/WebDriverAgentLib/Utilities/FBSettings.h b/WebDriverAgentLib/Utilities/FBSettings.h index afd37df97..08d8a7963 100644 --- a/WebDriverAgentLib/Utilities/FBSettings.h +++ b/WebDriverAgentLib/Utilities/FBSettings.h @@ -22,6 +22,7 @@ extern NSString* const FB_SETTING_SCREENSHOT_QUALITY; extern NSString* const FB_SETTING_KEYBOARD_AUTOCORRECTION; extern NSString* const FB_SETTING_KEYBOARD_PREDICTION; extern NSString* const FB_SETTING_SNAPSHOT_MAX_DEPTH; +extern NSString* const FB_SETTING_SNAPSHOT_MAX_CHILDREN; extern NSString* const FB_SETTING_USE_FIRST_MATCH; extern NSString* const FB_SETTING_BOUND_ELEMENTS_BY_INDEX; extern NSString* const FB_SETTING_REDUCE_MOTION; diff --git a/WebDriverAgentLib/Utilities/FBSettings.m b/WebDriverAgentLib/Utilities/FBSettings.m index 89f77a69c..65c6ed82f 100644 --- a/WebDriverAgentLib/Utilities/FBSettings.m +++ b/WebDriverAgentLib/Utilities/FBSettings.m @@ -18,6 +18,7 @@ NSString* const FB_SETTING_KEYBOARD_AUTOCORRECTION = @"keyboardAutocorrection"; NSString* const FB_SETTING_KEYBOARD_PREDICTION = @"keyboardPrediction"; NSString* const FB_SETTING_SNAPSHOT_MAX_DEPTH = @"snapshotMaxDepth"; +NSString* const FB_SETTING_SNAPSHOT_MAX_CHILDREN = @"snapshotMaxChildren"; NSString* const FB_SETTING_USE_FIRST_MATCH = @"useFirstMatch"; NSString* const FB_SETTING_BOUND_ELEMENTS_BY_INDEX = @"boundElementsByIndex"; NSString* const FB_SETTING_REDUCE_MOTION = @"reduceMotion"; From e7550f4e7328aca48bacfe1b28f4525ec3b5f4db Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Thu, 5 Mar 2026 22:53:18 -0800 Subject: [PATCH 02/10] add docstring --- .../Categories/XCAXClient_iOS+FBSnapshotReqParams.h | 7 +++++++ WebDriverAgentLib/Utilities/FBConfiguration.m | 2 -- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.h b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.h index 257092419..b4490809c 100644 --- a/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.h +++ b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.h @@ -15,7 +15,14 @@ NS_ASSUME_NONNULL_BEGIN extern NSString *const FBSnapshotMaxChildrenKey; extern NSString *const FBSnapshotMaxDepthKey; +/** + * Sets or overrides a custom snapshot request parameter by name. + */ void FBSetCustomParameterForElementSnapshot (NSString* name, id value); + +/** + * Removes a previously configured custom snapshot request parameter by name. + */ void FBRemoveCustomParameterForElementSnapshot (NSString* name); id __nullable FBGetCustomParameterForElementSnapshot (NSString *name); diff --git a/WebDriverAgentLib/Utilities/FBConfiguration.m b/WebDriverAgentLib/Utilities/FBConfiguration.m index 14e5a8d1f..a99050e03 100644 --- a/WebDriverAgentLib/Utilities/FBConfiguration.m +++ b/WebDriverAgentLib/Utilities/FBConfiguration.m @@ -6,8 +6,6 @@ * LICENSE file in the root directory of this source tree. */ -#import - #import "FBConfiguration.h" #import "AXSettings.h" From d434c02666aae58986b1a0461efb95b7d081deca Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Thu, 5 Mar 2026 22:54:40 -0800 Subject: [PATCH 03/10] update docstring --- WebDriverAgentLib/Utilities/FBConfiguration.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/WebDriverAgentLib/Utilities/FBConfiguration.h b/WebDriverAgentLib/Utilities/FBConfiguration.h index 7f86d035b..35fbf165a 100644 --- a/WebDriverAgentLib/Utilities/FBConfiguration.h +++ b/WebDriverAgentLib/Utilities/FBConfiguration.h @@ -208,16 +208,18 @@ typedef NS_ENUM(NSInteger, FBConfigurationKeyboardPreference) { + (int)snapshotMaxDepth; /** - Sets maximum element children for traversing elements tree in each snapshot while requesting XCElementSnapshot. - Used to set maxChildren value in a dictionary provided by XCAXClient_iOS's method defaultParams. - The original XCAXClient_iOS maxChildren value is set to INT_MAX. + Sets the maximum number of element children to traverse in each snapshot + while requesting XCElementSnapshot. + Used to set the `maxChildren` value in a dictionary provided by + XCAXClient_iOS's `defaultParameters` method. + The original XCAXClient_iOS `maxChildren` value is `INT_MAX`. @param maxChildren The number of maximum element children for traversing elements tree */ + (void)setSnapshotMaxChildren:(int)maxChildren; /** - @return The number of maximum depth for traversing elements tree + @return The maximum number of element children for traversing elements tree */ + (int)snapshotMaxChildren; From a2d3aff7733ebd2ae069e1be7b229d7aaa215910 Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Thu, 5 Mar 2026 23:13:48 -0800 Subject: [PATCH 04/10] simplify --- .../Categories/XCAXClient_iOS+FBSnapshotReqParams.m | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m index 4d571b70d..8228359b9 100644 --- a/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m +++ b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m @@ -38,9 +38,7 @@ void FBSetCustomParameterForElementSnapshot (NSString *name, id value) void FBRemoveCustomParameterForElementSnapshot (NSString *name) { - if (customRequestParameters && [customRequestParameters objectForKey:name]) { - [customRequestParameters removeObjectForKey:name]; - } + [customRequestParameters removeObjectForKey:name]; } id FBGetCustomParameterForElementSnapshot (NSString *name) From 837189c791fa948b749d744c05ccdff213458c2d Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Thu, 5 Mar 2026 23:19:17 -0800 Subject: [PATCH 05/10] remove a line --- WebDriverAgentLib/Utilities/FBConfiguration.m | 1 - 1 file changed, 1 deletion(-) diff --git a/WebDriverAgentLib/Utilities/FBConfiguration.m b/WebDriverAgentLib/Utilities/FBConfiguration.m index a99050e03..471daf266 100644 --- a/WebDriverAgentLib/Utilities/FBConfiguration.m +++ b/WebDriverAgentLib/Utilities/FBConfiguration.m @@ -385,7 +385,6 @@ + (int)snapshotMaxDepth return [FBGetCustomParameterForElementSnapshot(FBSnapshotMaxDepthKey) intValue]; } - + (void)setSnapshotMaxChildren:(int)maxChildren { FBSetCustomParameterForElementSnapshot(FBSnapshotMaxChildrenKey, @(maxChildren)); From bd6a71b90e8d7556125a3d1bffe8a0ac6132bd8e Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Thu, 5 Mar 2026 23:28:33 -0800 Subject: [PATCH 06/10] add nil check --- .../Categories/XCAXClient_iOS+FBSnapshotReqParams.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m index 8228359b9..740327b34 100644 --- a/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m +++ b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m @@ -38,6 +38,9 @@ void FBSetCustomParameterForElementSnapshot (NSString *name, id value) void FBRemoveCustomParameterForElementSnapshot (NSString *name) { + if (name.length == 0 || customRequestParameters == nil) { + return; + } [customRequestParameters removeObjectForKey:name]; } @@ -86,3 +89,4 @@ + (void)load #pragma clang diagnostic pop @end + From 2b06b9504fb225d376ac32b069e0435560c2b8ae Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Thu, 5 Mar 2026 23:29:06 -0800 Subject: [PATCH 07/10] remove last line --- .../Categories/XCAXClient_iOS+FBSnapshotReqParams.m | 1 - 1 file changed, 1 deletion(-) diff --git a/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m index 740327b34..4cd365105 100644 --- a/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m +++ b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m @@ -89,4 +89,3 @@ + (void)load #pragma clang diagnostic pop @end - From ef995d92328ae57337445921dedcdff9420591ff Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Fri, 6 Mar 2026 21:37:57 -0800 Subject: [PATCH 08/10] use INT_MAX --- .../Categories/XCAXClient_iOS+FBSnapshotReqParams.h | 8 -------- .../Categories/XCAXClient_iOS+FBSnapshotReqParams.m | 8 -------- WebDriverAgentLib/Utilities/FBConfiguration.m | 4 +++- 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.h b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.h index b4490809c..d15aeba68 100644 --- a/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.h +++ b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.h @@ -15,16 +15,8 @@ NS_ASSUME_NONNULL_BEGIN extern NSString *const FBSnapshotMaxChildrenKey; extern NSString *const FBSnapshotMaxDepthKey; -/** - * Sets or overrides a custom snapshot request parameter by name. - */ void FBSetCustomParameterForElementSnapshot (NSString* name, id value); -/** - * Removes a previously configured custom snapshot request parameter by name. - */ -void FBRemoveCustomParameterForElementSnapshot (NSString* name); - id __nullable FBGetCustomParameterForElementSnapshot (NSString *name); @interface XCAXClient_iOS (FBSnapshotReqParams) diff --git a/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m index 4cd365105..8698eb734 100644 --- a/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m +++ b/WebDriverAgentLib/Categories/XCAXClient_iOS+FBSnapshotReqParams.m @@ -36,14 +36,6 @@ void FBSetCustomParameterForElementSnapshot (NSString *name, id value) customRequestParameters[name] = value; } -void FBRemoveCustomParameterForElementSnapshot (NSString *name) -{ - if (name.length == 0 || customRequestParameters == nil) { - return; - } - [customRequestParameters removeObjectForKey:name]; -} - id FBGetCustomParameterForElementSnapshot (NSString *name) { return customRequestParameters[name]; diff --git a/WebDriverAgentLib/Utilities/FBConfiguration.m b/WebDriverAgentLib/Utilities/FBConfiguration.m index 471daf266..3e2ffb121 100644 --- a/WebDriverAgentLib/Utilities/FBConfiguration.m +++ b/WebDriverAgentLib/Utilities/FBConfiguration.m @@ -13,6 +13,7 @@ #import "TIPreferencesController.h" #include +#include #import #include "TargetConditionals.h" @@ -551,7 +552,7 @@ + (void)resetSessionSettings FBAnimationCoolOffTimeout = 2.; // 50 should be enough for the majority of the cases. The performance is acceptable for values up to 100. FBSetCustomParameterForElementSnapshot(FBSnapshotMaxDepthKey, @50); - FBRemoveCustomParameterForElementSnapshot(FBSnapshotMaxChildrenKey); + FBSetCustomParameterForElementSnapshot(FBSnapshotMaxChildrenKey, @INT_MAX); FBUseClearTextShortcut = YES; FBLimitXpathContextScope = YES; #if !TARGET_OS_TV @@ -720,3 +721,4 @@ + (BOOL)enforceCustomSnapshots } @end + From 5014a244453e64f4fd54cc3e70367ab9aeff9856 Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Fri, 6 Mar 2026 21:39:49 -0800 Subject: [PATCH 09/10] add type --- lib/types.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/types.ts b/lib/types.ts index a592b37d4..57524388d 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -12,6 +12,7 @@ export interface WDASettings { keyboardPrediction?: boolean; customSnapshotTimeout?: number; snapshotMaxDepth?: number; + snapshotMaxChildren?: number; useFirstMatch?: boolean; boundElementsByIndex?: boolean; reduceMotion?: boolean; From ac1166cbfec1b217b5aaf166cd2f78d04eab8b76 Mon Sep 17 00:00:00 2001 From: Kazuaki Matsuo Date: Fri, 6 Mar 2026 21:40:32 -0800 Subject: [PATCH 10/10] remove a line --- WebDriverAgentLib/Utilities/FBConfiguration.m | 1 - 1 file changed, 1 deletion(-) diff --git a/WebDriverAgentLib/Utilities/FBConfiguration.m b/WebDriverAgentLib/Utilities/FBConfiguration.m index 3e2ffb121..e6ce8d52f 100644 --- a/WebDriverAgentLib/Utilities/FBConfiguration.m +++ b/WebDriverAgentLib/Utilities/FBConfiguration.m @@ -721,4 +721,3 @@ + (BOOL)enforceCustomSnapshots } @end -