fix test runner does not keepalive

Signed-off-by: Ronni Skansing <rskansing@gmail.com>
This commit is contained in:
Ronni Skansing
2026-05-14 11:14:15 +02:00
parent b8c89c43df
commit 404ecd205b
2 changed files with 12 additions and 0 deletions
+4
View File
@@ -370,6 +370,10 @@ func (m *RemoteBrowserController) RunByID(g *gin.Context) {
}
}()
// NoKeepAlive=true so keepAlive() in test scripts returns immediately instead
// of parking the browser — closing the test panel must always stop cleanly.
runner.NoKeepAlive = true
// Run the script in a goroutine; Events channel is closed when done.
go runner.Run(ctx) //nolint:errcheck
+8
View File
@@ -72,6 +72,10 @@ type Runner struct {
// ExecPath is the server-configured Chrome binary path (from config.json,
// not user-supplied). Empty = Rod auto-download.
ExecPath string
// NoKeepAlive disables the keepAlive() parking behaviour. When true,
// keepAlive() returns immediately so the script exits normally. Used by
// the test runner to prevent leaking browsers when the test panel closes.
NoKeepAlive bool
Events chan RunEvent // server → client
Incoming chan IncomingMsg // client → script (victim events / test injections)
// BrowserCh receives the *rod.Page as soon as newSession() spawns the browser.
@@ -386,6 +390,10 @@ func (r *Runner) Run(ctx context.Context) error {
// is available for streaming. It blocks until the runner context
// is cancelled (e.g. the admin closes the live session).
session.Set("keepAlive", func(call goja.FunctionCall) goja.Value {
if r.NoKeepAlive {
emitter.log("[session] keepAlive skipped (test mode)")
return goja.Undefined()
}
emitter.log("[session] keeping alive for remote takeover")
select {
case r.LiveCh <- page: