Skip to content

Commit

Permalink
crocochrome: instantiate and store a chromium client
Browse files Browse the repository at this point in the history
  • Loading branch information
roobre committed Jul 9, 2024
1 parent dd11a07 commit e064a55
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions crocochrome.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ import (
)

type Supervisor struct {
opts Options
logger *slog.Logger
opts Options
logger *slog.Logger
cclient *chromium.Client
// sessions is a map from session ID to a cancel function that kills the session when called.
// Currently, crocochrome ensures that only one session is active at a time, by killing all other active sessions
// when a new one is creating (by traversing this map).
Expand Down Expand Up @@ -75,6 +76,7 @@ func New(logger *slog.Logger, opts Options) *Supervisor {
return &Supervisor{
opts: opts.withDefaults(),
logger: logger,
cclient: chromium.NewClient(),
sessions: map[string]context.CancelFunc{},
}
}
Expand Down Expand Up @@ -157,7 +159,7 @@ func (s *Supervisor) Session() (SessionInfo, error) {
versionCtx, versionCancel := context.WithTimeout(ctx, 2*time.Second)
defer versionCancel()

version, err := chromium.Version(versionCtx, net.JoinHostPort("localhost", s.opts.ChromiumPort))
version, err := s.cclient.Version(versionCtx, net.JoinHostPort("localhost", s.opts.ChromiumPort))
if err != nil {
logger.Error("could not get chromium info", "err", err)
s.delete(id) // We were not able to connect to chrome, the session is borked.
Expand Down

0 comments on commit e064a55

Please sign in to comment.