@@ -65,22 +65,7 @@ type Web struct {
6565
6666// New returns an initialised instance of Web struct
6767func New (ctx context.Context , conf * WebConfig ) * Web {
68- l := launcher .New ()
69-
70- browserExecPath , found := conf .CustomChromeExecutable , false
71- // try default chrome location if custom location is not specified
72- if browserExecPath == "" {
73- if browserExecPath , found = launcher .LookPath (); browserExecPath != "" && found {
74- l .Bin (browserExecPath )
75- }
76- }
77-
78- // common set up
79- l .Devtools (false ).
80- UserDataDir (conf .datadir ).
81- Headless (conf .headless ).
82- NoSandbox (conf .noSandbox ).
83- Leakless (conf .leakless )
68+ l := BuildLauncher (ctx , conf )
8469
8570 url := l .MustLaunch ()
8671
@@ -98,6 +83,26 @@ func New(ctx context.Context, conf *WebConfig) *Web {
9883 return web
9984}
10085
86+ func BuildLauncher (ctx context.Context , conf * WebConfig ) * launcher.Launcher {
87+ l := launcher .New ()
88+
89+ if conf .CustomChromeExecutable != "" {
90+ l .Bin (conf .CustomChromeExecutable )
91+ }
92+ // try default locations if custom location is not specified and default location exists
93+ if defaultExecPath , found := launcher .LookPath (); conf .CustomChromeExecutable == "" && defaultExecPath != "" && found {
94+ l .Bin (defaultExecPath )
95+ }
96+
97+ // common set up
98+ l .Devtools (false ).
99+ UserDataDir (conf .datadir ).
100+ Headless (conf .headless ).
101+ NoSandbox (conf .noSandbox ).
102+ Leakless (conf .leakless )
103+ return l
104+ }
105+
101106func (web * Web ) WithConfig (conf * WebConfig ) * Web {
102107 web .conf = conf
103108 return web
@@ -217,7 +222,7 @@ func (web *Web) GetSSOCredentials(conf credentialexchange.CredentialConfig) (str
217222}
218223
219224func (web * Web ) MustClose () {
220- // swallows errors here - until a structured logger
225+ // swallows errors here - until a structured logger
221226 _ = web .browser .Close ()
222227 utils .Sleep (0.5 )
223228 // remove process just in case
0 commit comments