@@ -36,10 +36,7 @@ public class ChromiumProcess : IDisposable
3636 "--disable-translate" ,
3737 "--metrics-recording-only" ,
3838 "--no-first-run" ,
39- "--safebrowsing-disable-auto-update"
40- } ;
41-
42- internal static readonly string [ ] AutomationArgs = {
39+ "--safebrowsing-disable-auto-update" ,
4340 "--enable-automation" ,
4441 "--password-store=basic" ,
4542 "--use-mock-keychain"
@@ -205,69 +202,71 @@ public async Task<bool> WaitForExitAsync(TimeSpan? timeout)
205202
206203 private static ( List < string > chromiumArgs , TempDirectory tempUserDataDir ) PrepareChromiumArgs ( LaunchOptions options )
207204 {
208- var chromiumArgs = new List < string > ( DefaultArgs ) ;
209- TempDirectory tempUserDataDir = null ;
210205
211- if ( options . AppMode )
206+ var chromiumArgs = new List < string > ( ) ;
207+
208+ if ( ! options . IgnoreDefaultArgs )
212209 {
213- options . Headless = false ;
210+ chromiumArgs . AddRange ( GetDefaultArgs ( options ) ) ;
211+ }
212+ else if ( options . IgnoredDefaultArgs ? . Length > 0 )
213+ {
214+ chromiumArgs . AddRange ( GetDefaultArgs ( options ) . Except ( options . IgnoredDefaultArgs ) ) ;
214215 }
215216 else
216217 {
217- chromiumArgs . AddRange ( AutomationArgs ) ;
218+ chromiumArgs . AddRange ( options . Args ) ;
218219 }
219220
220- if ( ! options . IgnoreDefaultArgs ||
221- ! chromiumArgs . Any ( argument => argument . StartsWith ( "--remote-debugging-" , StringComparison . Ordinal ) ) )
221+ TempDirectory tempUserDataDir = null ;
222+
223+ if ( ! chromiumArgs . Any ( argument => argument . StartsWith ( "--remote-debugging-" , StringComparison . Ordinal ) ) )
222224 {
223225 chromiumArgs . Add ( "--remote-debugging-port=0" ) ;
224226 }
225227
226- var userDataDirOption = options . Args . FirstOrDefault ( i => i . StartsWith ( UserDataDirArgument , StringComparison . Ordinal ) ) ;
228+ var userDataDirOption = chromiumArgs . FirstOrDefault ( i => i . StartsWith ( UserDataDirArgument , StringComparison . Ordinal ) ) ;
227229 if ( string . IsNullOrEmpty ( userDataDirOption ) )
228230 {
229- if ( string . IsNullOrEmpty ( options . UserDataDir ) )
230- {
231- tempUserDataDir = new TempDirectory ( ) ;
232- chromiumArgs . Add ( $ "{ UserDataDirArgument } ={ tempUserDataDir . Path . Quote ( ) } ") ;
233- }
234- else
235- {
236- chromiumArgs . Add ( $ "{ UserDataDirArgument } ={ options . UserDataDir . Quote ( ) } ") ;
237- }
231+ tempUserDataDir = new TempDirectory ( ) ;
232+ chromiumArgs . Add ( $ "{ UserDataDirArgument } ={ tempUserDataDir . Path . Quote ( ) } ") ;
238233 }
239- else
234+
235+ return ( chromiumArgs , tempUserDataDir ) ;
236+ }
237+
238+ internal static string [ ] GetDefaultArgs ( LaunchOptions options )
239+ {
240+ var chromeArguments = new List < string > ( DefaultArgs ) ;
241+
242+ if ( ! string . IsNullOrEmpty ( options . UserDataDir ) )
240243 {
241- options . UserDataDir = userDataDirOption . Replace ( $ "{ UserDataDirArgument } =" , string . Empty ) . UnQuote ( ) ;
244+ chromeArguments . Add ( $ "{ UserDataDirArgument } ={ options . UserDataDir . Quote ( ) } " ) ;
242245 }
243-
244246 if ( options . Devtools )
245247 {
246- chromiumArgs . Add ( "--auto-open-devtools-for-tabs" ) ;
247- options . Headless = false ;
248+ chromeArguments . Add ( "--auto-open-devtools-for-tabs" ) ;
248249 }
249-
250250 if ( options . Headless )
251251 {
252- chromiumArgs . AddRange ( new [ ] {
252+ chromeArguments . AddRange ( new [ ] {
253253 "--headless" ,
254- "--disable-gpu" ,
255254 "--hide-scrollbars" ,
256255 "--mute-audio"
257256 } ) ;
257+ if ( BrowserFetcher . GetCurrentPlatform ( ) == Platform . Win32 )
258+ {
259+ chromeArguments . Add ( "--disable-gpu" ) ;
260+ }
258261 }
259262
260263 if ( options . Args . All ( arg => arg . StartsWith ( "-" , StringComparison . Ordinal ) ) )
261264 {
262- chromiumArgs . Add ( "about:blank" ) ;
263- }
264-
265- if ( options . Args . Any ( ) )
266- {
267- chromiumArgs . AddRange ( options . Args ) ;
265+ chromeArguments . Add ( "about:blank" ) ;
268266 }
269267
270- return ( chromiumArgs , tempUserDataDir ) ;
268+ chromeArguments . AddRange ( options . Args ) ;
269+ return chromeArguments . ToArray ( ) ;
271270 }
272271
273272 private static void SetEnvVariables ( IDictionary < string , string > environment , IDictionary < string , string > customEnv , IDictionary realEnv )
@@ -601,12 +600,7 @@ private class ExitingState : State
601600 {
602601 public Task EnterFromAsync ( ChromiumProcess p , State fromState , TimeSpan timeout )
603602 {
604- if ( ! TryEnter ( p , fromState ) )
605- {
606- return p . _currentState . ExitAsync ( p , timeout ) ;
607- }
608-
609- return ExitAsync ( p , timeout ) ;
603+ return ! TryEnter ( p , fromState ) ? p . _currentState . ExitAsync ( p , timeout ) : ExitAsync ( p , timeout ) ;
610604 }
611605
612606 public override async Task ExitAsync ( ChromiumProcess p , TimeSpan timeout )
0 commit comments