diff --git a/evaluator.go b/evaluator.go index 5768b854..456103d5 100644 --- a/evaluator.go +++ b/evaluator.go @@ -42,7 +42,12 @@ func Evaluate(ctx context.Context, tape string, out io.Writer, opts ...Evaluator if err := v.Start(); err != nil { return []error{err} } - defer func() { _ = v.close() }() + defer func() { + _ = v.close() + if v.tty != nil && v.tty.Process != nil { + _ = v.tty.Process.Kill() + } + }() // Let's wait until we can access the window.term variable. // diff --git a/vhs.go b/vhs.go index 235e7b42..ad645a2b 100644 --- a/vhs.go +++ b/vhs.go @@ -140,11 +140,14 @@ func (vhs *VHS) Start() error { enableNoSandbox := os.Getenv("VHS_NO_SANDBOX") != "" u, err := launcher.New().Leakless(false).Bin(path).NoSandbox(enableNoSandbox).Launch() if err != nil { + _ = vhs.tty.Process.Kill() return fmt.Errorf("could not launch browser: %w", err) } browser := rod.New().ControlURL(u).MustConnect() page, err := browser.Page(proto.TargetCreateTarget{URL: fmt.Sprintf("http://localhost:%d", port)}) if err != nil { + browser.MustClose() + _ = vhs.tty.Process.Kill() return fmt.Errorf("could not open ttyd: %w", err) }