@@ -13,7 +13,7 @@ namespace PuppeteerSharp
1313{
1414 public class Launcher
1515 {
16- private static string [ ] _defaultArgs = {
16+ private static readonly string [ ] _defaultArgs = {
1717 "--disable-background-networking" ,
1818 "--disable-background-timer-throttling" ,
1919 "--disable-client-side-phishing-detection" ,
@@ -30,7 +30,7 @@ public class Launcher
3030 "--safebrowsing-disable-auto-update" ,
3131 } ;
3232
33- public static string [ ] _automationArgs = {
33+ public static readonly string [ ] _automationArgs = {
3434 "--enable-automation" ,
3535 "--password-store=basic" ,
3636 "--use-mock-keychain"
@@ -42,40 +42,39 @@ public class Launcher
4242 private Connection _connection = null ;
4343 private Timer _timer = null ;
4444
45- internal async Task < Browser > LaunchAsync ( Dictionary < string , object > options , int chromiumRevision )
45+ internal async Task < Browser > LaunchAsync ( LaunchOptions options , int chromiumRevision )
4646 {
4747 var chromeArguments = new List < string > ( _defaultArgs ) ;
4848
49- if ( options . ContainsKey ( "appMode" ) )
49+ if ( options . AppMode )
5050 {
51- options [ "headless" ] = false ;
51+ options . Headless = false ;
5252 }
5353 else
5454 {
5555 chromeArguments . AddRange ( _automationArgs ) ;
5656 }
5757
58- if ( options . ContainsKey ( "args" ) &&
59- ( ( string [ ] ) options [ "args" ] ) . Any ( i => i . StartsWith ( "--user-data-dir" , StringComparison . Ordinal ) ) )
58+ if ( options . Args . Any ( i => i . StartsWith ( "--user-data-dir" , StringComparison . Ordinal ) ) )
6059 {
61- if ( ! options . ContainsKey ( "userDataDir" ) )
60+ if ( string . IsNullOrEmpty ( options . UserDataDir ) )
6261 {
6362 _temporaryUserDataDir = GetTemporaryDirectory ( ) ;
6463 chromeArguments . Add ( $ "--user-data-dir=${ _temporaryUserDataDir } ") ;
6564 }
6665 else
6766 {
68- chromeArguments . Add ( $ "--user-data-dir=${ options [ "userDataDir" ] } ") ;
67+ chromeArguments . Add ( $ "--user-data-dir=${ options . UserDataDir } ") ;
6968 }
7069 }
7170
72- if ( options . TryGetValue ( "devtools" , out var hasDevTools ) && ( bool ) hasDevTools )
71+ if ( options . Devtools )
7372 {
7473 chromeArguments . Add ( "--auto-open-devtools-for-tabs" ) ;
75- options [ "headless" ] = false ;
74+ options . Headless = false ;
7675 }
7776
78- if ( options . TryGetValue ( "headless" , out var isHeadless ) && ( bool ) isHeadless )
77+ if ( options . Headless )
7978 {
8079 chromeArguments . AddRange ( new [ ] {
8180 "--headless" ,
@@ -85,7 +84,7 @@ internal async Task<Browser> LaunchAsync(Dictionary<string, object> options, int
8584 } ) ;
8685 }
8786
88- var chromeExecutable = ( options . GetValueOrDefault ( "executablePath" ) ?? "" ) . ToString ( ) ;
87+ var chromeExecutable = options . ExecutablePath ;
8988
9089 if ( string . IsNullOrEmpty ( chromeExecutable ) )
9190 {
@@ -94,20 +93,18 @@ internal async Task<Browser> LaunchAsync(Dictionary<string, object> options, int
9493 chromeExecutable = revisionInfo . ExecutablePath ;
9594 }
9695
97- if ( options . ContainsKey ( "args" ) )
96+ if ( options . Args . Any ( ) )
9897 {
99- chromeArguments . AddRange ( ( string [ ] ) options [ "args" ] ) ;
98+ chromeArguments . AddRange ( options . Args ) ;
10099 }
101100
102101 _chromeProcess = new Process ( ) ;
103102 _chromeProcess . StartInfo . FileName = chromeExecutable ;
104103 _chromeProcess . StartInfo . Arguments = string . Join ( " " , chromeArguments ) ;
105104
106- SetEnvVariables ( _chromeProcess . StartInfo . Environment ,
107- options . ContainsKey ( "env" ) ? ( IDictionary < string , string > ) options [ "env" ] : null ,
108- ( IDictionary ) Environment . GetEnvironmentVariables ( ) ) ;
105+ SetEnvVariables ( _chromeProcess . StartInfo . Environment , options . Env , Environment . GetEnvironmentVariables ( ) ) ;
109106
110- if ( ! options . ContainsKey ( "dumpio" ) )
107+ if ( ! options . DumpIO )
111108 {
112109 _chromeProcess . StartInfo . RedirectStandardOutput = false ;
113110 _chromeProcess . StartInfo . RedirectStandardError = false ;
@@ -121,11 +118,9 @@ internal async Task<Browser> LaunchAsync(Dictionary<string, object> options, int
121118
122119 try
123120 {
124- var connectionDelay = ( int ) ( options . GetValueOrDefault ( "slowMo" ) ?? 0 ) ;
125- var browserWSEndpoint = await WaitForEndpoint ( _chromeProcess ,
126- ( int ) ( options . GetValueOrDefault ( "timeout" ) ?? 30 * 100 ) ,
127- options . ContainsKey ( "dumpio" ) ) ;
128- var keepAliveInterval = options . ContainsKey ( "keepAliveInterval" ) ? Convert . ToInt32 ( options [ "keepAliveInterval" ] ) : 30 ;
121+ var connectionDelay = options . SlowMo ;
122+ var browserWSEndpoint = await WaitForEndpoint ( _chromeProcess , options . Timeout , options . DumpIO ) ;
123+ var keepAliveInterval = options . KeepAliveInterval ;
129124
130125 _connection = await Connection . Create ( browserWSEndpoint , connectionDelay , keepAliveInterval ) ;
131126 return await Browser . CreateAsync ( _connection , options , KillChrome ) ;
0 commit comments