@@ -14,9 +14,9 @@ import (
14
14
"strconv"
15
15
"time"
16
16
17
- "golang.org/x/xerrors"
18
-
17
+ "github.com/pkg/browser"
19
18
"go.coder.com/flog"
19
+ "golang.org/x/xerrors"
20
20
)
21
21
22
22
func init () {
@@ -139,26 +139,30 @@ func openBrowser(url string) {
139
139
var openCmd * exec.Cmd
140
140
switch {
141
141
case commandExists ("google-chrome" ):
142
- openCmd = exec .Command ("google-chrome" , fmtChromeOptions (url )... )
142
+ openCmd = exec .Command ("google-chrome" , chromeOptions (url )... )
143
143
case commandExists ("chromium" ):
144
- openCmd = exec .Command ("chromium" , fmtChromeOptions (url )... )
144
+ openCmd = exec .Command ("chromium" , chromeOptions (url )... )
145
145
case commandExists ("chromium-browser" ):
146
- openCmd = exec .Command ("chromium-browser" , fmtChromeOptions (url )... )
147
- case commandExists ("firefox" ):
148
- openCmd = exec .Command ("firefox" , "--url=" + url , "-safe-mode" )
146
+ openCmd = exec .Command ("chromium-browser" , chromeOptions (url )... )
149
147
case pathExists ("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" ):
150
- openCmd = exec .Command ("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" , fmtChromeOptions (url )... )
148
+ openCmd = exec .Command ("/Applications/Google Chrome.app/Contents/MacOS/Google Chrome" , chromeOptions (url )... )
151
149
default :
152
- flog .Info ("unable to find a browser to open: sshcode only supports firefox, chrome, and chromium" )
150
+ err := browser .OpenURL (url )
151
+ if err != nil {
152
+ flog .Error ("failed to open browser: %v" , err )
153
+ }
154
+ return
153
155
}
154
156
157
+ // We do not use CombinedOutput because if there is no chrome instance, this will block
158
+ // and become the parent process instead of using an existing chrome instance.
155
159
err := openCmd .Start ()
156
160
if err != nil {
157
- flog .Fatal ("failed to open browser: %v" , err )
161
+ flog .Error ("failed to open browser: %v" , err )
158
162
}
159
163
}
160
164
161
- func fmtChromeOptions (url string ) []string {
165
+ func chromeOptions (url string ) []string {
162
166
return []string {"--app=" + url , "--disable-extensions" , "--disable-plugins" }
163
167
}
164
168
0 commit comments