@@ -11,7 +11,7 @@ public static class SearchWeb
1111 /// Opens search in a new browser. If no browser path is passed in then Chrome is used.
1212 /// Leave browser path blank to use Chrome.
1313 /// </summary>
14- public static void NewBrowserWindow ( this string url , string browserPath )
14+ public static void NewBrowserWindow ( this string url , string browserPath = "" )
1515 {
1616 var browserExecutableName = browserPath ?
1717 . Split ( new [ ] { Path . DirectorySeparatorChar } , StringSplitOptions . None )
@@ -22,41 +22,47 @@ public static void NewBrowserWindow(this string url, string browserPath)
2222 // Internet Explorer will open url in new browser window, and does not take the --new-window parameter
2323 var browserArguements = browserExecutableName == "iexplore.exe" ? url : "--new-window " + url ;
2424
25+ var psi = new ProcessStartInfo
26+ {
27+ FileName = browser ,
28+ Arguments = browserArguements ,
29+ UseShellExecute = true
30+ } ;
31+
2532 try
2633 {
27- Process . Start ( browser , browserArguements ) ;
34+ Process . Start ( psi ) ;
2835 }
2936 catch ( System . ComponentModel . Win32Exception )
3037 {
31- var psi = new ProcessStartInfo
32- {
33- FileName = url ,
34- UseShellExecute = true
35- } ;
36- Process . Start ( psi ) ;
38+ Process . Start ( new ProcessStartInfo { FileName = url , UseShellExecute = true } ) ;
3739 }
3840 }
3941
4042 /// <summary>
4143 /// Opens search as a tab in the default browser chosen in Windows settings.
4244 /// </summary>
43- public static void NewTabInBrowser ( this string url , string browserPath )
45+ public static void NewTabInBrowser ( this string url , string browserPath = "" )
4446 {
47+ var psi = new ProcessStartInfo ( ) { UseShellExecute = true } ;
4548 try
4649 {
4750 if ( ! string . IsNullOrEmpty ( browserPath ) )
4851 {
49- Process . Start ( browserPath , url ) ;
52+ psi . FileName = browserPath ;
53+ psi . Arguments = url ;
5054 }
5155 else
5256 {
53- Process . Start ( url ) ;
57+ psi . FileName = url ;
5458 }
59+
60+ Process . Start ( psi ) ;
5561 }
56- // This error may be thrown for Process.Start(browserPath, url)
62+ // This error may be thrown if browser path is incorrect
5763 catch ( System . ComponentModel . Win32Exception )
5864 {
59- Process . Start ( url ) ;
65+ Process . Start ( new ProcessStartInfo { FileName = url , UseShellExecute = true } ) ;
6066 }
6167 }
6268 }
0 commit comments