@@ -140,15 +140,36 @@ export abstract class BrowserPlugin<
140140 async launch (
141141 launchContext : LaunchContext < Library , LibraryOptions , LaunchResult , NewPageOptions , NewPageResult > = this . createLaunchContext ( ) ,
142142 ) : Promise < LaunchResult > {
143- const { proxyUrl } = launchContext ;
143+ const { proxyUrl, launchOptions } : { proxyUrl ?: string ; launchOptions : Record < string , any > } = launchContext ;
144144
145145 if ( proxyUrl ) {
146146 await this . _addProxyToLaunchOptions ( launchContext ) ;
147147 }
148148
149+ if ( this . _isChromiumBasedBrowser ( launchContext ) ) {
150+ // This will set the args for chromium based browsers to hide the webdriver.
151+ launchOptions . args = this . _mergeArgsToHideWebdriver ( launchOptions . args ) ;
152+ }
153+
149154 return this . _launch ( launchContext ) ;
150155 }
151156
157+ private _mergeArgsToHideWebdriver ( originalArgs : string [ ] ) : string [ ] {
158+ if ( ! originalArgs ?. length ) {
159+ return [ '--disable-blink-features=AutomationControlled' ] ;
160+ }
161+
162+ const argumentIndex = originalArgs . findIndex ( ( arg : string ) => arg . startsWith ( '--disable-blink-features=' ) ) ;
163+
164+ if ( argumentIndex !== - 1 ) {
165+ originalArgs [ argumentIndex ] += ',AutomationControlled' ;
166+ } else {
167+ originalArgs . push ( '--disable-blink-features=AutomationControlled' ) ;
168+ }
169+
170+ return originalArgs ;
171+ } ;
172+
152173 /**
153174 * @private
154175 */
@@ -158,6 +179,12 @@ export abstract class BrowserPlugin<
158179 throwImplementationNeeded ( '_addProxyToLaunchOptions' ) ;
159180 }
160181
182+ // @ts -expect-error Give runtime error as well as compile time
183+ // eslint-disable-next-line space-before-function-paren, @typescript-eslint/no-unused-vars, max-len
184+ protected abstract _isChromiumBasedBrowser ( launchContext : LaunchContext < Library , LibraryOptions , LaunchResult , NewPageOptions , NewPageResult > ) : boolean {
185+ throwImplementationNeeded ( '_isChromiumBasedBrowser' ) ;
186+ }
187+
161188 /**
162189 * @private
163190 */
0 commit comments