Skip to content

High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.

fix: enable the runtime domain synchronously so early console entries are not dropped

Luigi Agostiea784ee7ca2b
diff --git a/internal/bridge/console_capture.go b/internal/bridge/console_capture.go
index 2c58b425..5fa8a24c 100644
--- a/internal/bridge/console_capture.go
+++ b/internal/bridge/console_capture.go
@@ -121,13 +121,23 @@ func (tm *TabManager) setupConsoleCapture(ctx context.Context, rawCDPID string)
}
})
- go func() {
- _ = chromedp.Run(ctx, chromedp.ActionFunc(func(c context.Context) error {
- return runtime.Enable().Do(c)
- }))
- }()
+ // Enable the Runtime domain synchronously before returning. Doing this in
+ // a detached goroutine raced page load: under CPU contention the page's
+ // synchronous console.* calls fired before Runtime.enable landed, and
+ // Chrome only dispatches consoleAPICalled events after the domain is
+ // enabled — so early console/exception entries were silently dropped.
+ // Bounded so a wedged target cannot stall tab creation.
+ enableCtx, cancel := context.WithTimeout(ctx, runtimeEnableTimeout)
+ defer cancel()
+ _ = chromedp.Run(enableCtx, chromedp.ActionFunc(func(c context.Context) error {
+ return runtime.Enable().Do(c)
+ }))
}
+// runtimeEnableTimeout bounds the synchronous Runtime.enable in
+// setupConsoleCapture; enabling normally takes a couple of milliseconds.
+const runtimeEnableTimeout = 5 * time.Second
+
func (tm *TabManager) shouldEagerlyCaptureConsole() bool {
if tm == nil || tm.config == nil {
return true