diff --git a/backend/remotebrowser/runner.go b/backend/remotebrowser/runner.go index 9a13aea..e3dcc58 100644 --- a/backend/remotebrowser/runner.go +++ b/backend/remotebrowser/runner.go @@ -574,6 +574,13 @@ func (r *Runner) Run(ctx context.Context) error { emitter.errorf(fmt.Sprintf("browser launch failed: %v", err)) return goja.Undefined() } + // Kill and clean up Chrome when the session ends. Without this, stopping + // a run before s.close() is called leaves a zombie Chrome process (~200-300 MB). + go func() { + <-outerCtx.Done() + l.Kill() + l.Cleanup() + }() browser = rod.New().ControlURL(u).Context(outerCtx) if err := browser.Connect(); err != nil { emitter.errorf(fmt.Sprintf("browser connect failed: %v", err))