Skip to content

Commit

Permalink
propagate verbose to playwright
Browse files Browse the repository at this point in the history
  • Loading branch information
rusq committed Dec 22, 2023
1 parent 5e94eb5 commit 9c88b58
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 10 deletions.
6 changes: 6 additions & 0 deletions auth/browser/browser.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ func OptTimeout(d time.Duration) Option {
}
}

func OptVerbose(b bool) Option {
return func(c *Client) {
c.verbose = b
}
}

func (e *Browser) Set(v string) error {
v = strings.ToLower(v)
for i := 0; i < len(_Browser_index)-1; i++ {
Expand Down
16 changes: 12 additions & 4 deletions auth/browser/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type Client struct {
pageClosed chan bool // will receive a notification that the page is closed prematurely.
br Browser
loginTimeout float64 // slack login page timeout in milliseconds.
verbose bool
}

var Logger logger.Interface = logger.Default
Expand All @@ -48,19 +49,22 @@ func New(workspace string, opts ...Option) (*Client, error) {
pageClosed: make(chan bool, 1),
br: Bfirefox,
loginTimeout: float64(DefLoginTimeout.Milliseconds()),
verbose: false,
}
for _, opt := range opts {
opt(cl)
}
l().Debugf("browser=%s, timeout=%f", cl.br, cl.loginTimeout)
runopts := &playwright.RunOptions{
Browsers: []string{cl.br.String()},
Verbose: cl.verbose,
}
if err := installFn(runopts); err != nil {
if !strings.Contains(err.Error(), "could not run driver") || runtime.GOOS == "windows" {
return nil, err
return nil, fmt.Errorf("can't install the browser: %w", err)
}
if err := pwRepair(runopts); err != nil {
return nil, err
return nil, fmt.Errorf("failed to repair the browser installation: %w", err)
}
}
return cl, nil
Expand Down Expand Up @@ -235,23 +239,27 @@ func pwRepair(runopts *playwright.RunOptions) error {
}

// Reinstall cleans and reinstalls the browser.
func Reinstall(browser string) error {
func Reinstall(browser Browser, verbose bool) error {
runopts := &playwright.RunOptions{
Browsers: []string{browser},
Browsers: []string{browser.String()},
Verbose: verbose,
}
return reinstall(runopts)
}

func reinstall(runopts *playwright.RunOptions) error {
l().Debugf("reinstalling browser: %s", runopts.Browsers[0])
drv, err := newDriverFn(runopts)
if err != nil {
return err
}
l().Debugf("removing %s", drv.DriverDirectory)
if err := os.RemoveAll(drv.DriverDirectory); err != nil {
return err
}

// attempt to reinstall
l().Debugf("reinstalling %s", drv.DriverDirectory)
if err := installFn(runopts); err != nil {
// we did everything we could, but it still failed.
return err
Expand Down
13 changes: 7 additions & 6 deletions cmd/slackdump/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,6 @@ func main() {
return
}
}
if params.browserReinstall {
dlog.Printf("Reinstalling %s", params.browser)
if err := browser.Reinstall(params.browser.String()); err != nil {
dlog.Fatalf("browser reinstall error: %s", err)
}
}
if errors.Is(cfgErr, config.ErrNothingToDo) {
// if the user hasn't provided any required flags, let's offer
// an interactive prompt to fill them.
Expand Down Expand Up @@ -141,6 +135,13 @@ func run(ctx context.Context, p params) error {
ctx, task := trace.NewTask(ctx, "main.run")
defer task.End()

if p.browserReinstall {
dlog.Printf("Reinstalling %s", p.browser)
if err := browser.Reinstall(p.browser, p.verbose); err != nil {
return fmt.Errorf("error reinstalling %s: %w", p.browser, err)
}
}

provider, err := app.InitProvider(ctx, p.appCfg.Options.CacheDir, p.workspace, p.creds, p.browser)
if err != nil {
return err
Expand Down

0 comments on commit 9c88b58

Please sign in to comment.