Skip to content

Commit 760f10f

Browse files
committed
Pass an identifier for the client into RunHeadless
so that we can distinguish output from differrent instances
1 parent 399a1de commit 760f10f

2 files changed

Lines changed: 6 additions & 6 deletions

File tree

internal/api/js/chrome/chrome.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,15 @@ type Browser struct {
7070
Cancel func()
7171
}
7272

73-
func RunHeadless(onConsoleLog func(s string), requiresPersistence bool, listenPort int) (*Browser, error) {
73+
func RunHeadless(logPrefix string, onConsoleLog func(s string), requiresPersistence bool, listenPort int) (*Browser, error) {
7474
ansiRedForeground := "\x1b[31m"
7575
ansiYellowForeground := "\x1b[33m"
7676
ansiResetForeground := "\x1b[39m"
7777

7878
// colorifyError returns a log format function which prints its input with a given prefix and colour.
7979
colorifyError := func(colour string, prefix string) func(format string, args ...any) {
8080
return func(format string, args ...any) {
81-
format = ansiRedForeground + time.Now().Format(time.RFC3339) + " [chromedp: " + prefix + "] " + format + ansiResetForeground + "\n"
81+
format = ansiRedForeground + time.Now().Format(time.RFC3339) + " " + logPrefix + "[chromedp " + prefix + "] " + format + ansiResetForeground + "\n"
8282
fmt.Printf(format, args...)
8383
}
8484
}
@@ -137,10 +137,10 @@ func RunHeadless(onConsoleLog func(s string), requiresPersistence bool, listenPo
137137
panic(err)
138138
}
139139
baseJSURL = "http://" + ln.Addr().String()
140-
fmt.Println("JS SDK listening on", baseJSURL)
140+
fmt.Println(logPrefix, "JS SDK wrapper listening on", baseJSURL)
141141
wg.Done()
142-
srv.Serve(ln)
143-
fmt.Println("JS SDK closing webserver")
142+
err = srv.Serve(ln)
143+
fmt.Printf("%s Closing webserver for JS SDK wrapper at %s: %v\n", logPrefix, baseJSURL, err)
144144
}
145145
go startServer()
146146
wg.Wait()

internal/api/js/js.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ func NewJSClient(t ct.TestLike, opts api.ClientCreationOpts) (api.Client, error)
6969
verificationChannelMu: &sync.Mutex{},
7070
}
7171
portKey := opts.UserID + opts.DeviceID
72-
browser, err := chrome.RunHeadless(func(s string) {
72+
browser, err := chrome.RunHeadless(fmt.Sprintf("[JSClient %s,%s]", opts.UserID, opts.DeviceID), func(s string) {
7373
writeToLog("[%s,%s] console.log %s\n", opts.UserID, opts.DeviceID, s)
7474

7575
msg := unpackControlMessage(t, s)

0 commit comments

Comments
 (0)