From f5a990492abece63461df317dc087d0dea421788 Mon Sep 17 00:00:00 2001 From: Ronni Skansing Date: Sun, 17 May 2026 19:48:02 +0200 Subject: [PATCH] debug remote browser Signed-off-by: Ronni Skansing --- backend/remotebrowser/runner.go | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/backend/remotebrowser/runner.go b/backend/remotebrowser/runner.go index d64cad4..611e504 100644 --- a/backend/remotebrowser/runner.go +++ b/backend/remotebrowser/runner.go @@ -1,6 +1,7 @@ package remotebrowser import ( + "bytes" "context" "encoding/json" "errors" @@ -95,6 +96,29 @@ func resolveBrowserRootDir() (string, error) { return filepath.Join(filepath.Dir(execPath), "data", "browser"), nil } +// chromeSterrWriter is an io.Writer that forwards Chrome stdout/stderr lines to +// the session emitter so crash messages appear in the operator event log. +type chromeSterrWriter struct { + emitter *channelEmitter + buf []byte +} + +func (w *chromeSterrWriter) Write(p []byte) (int, error) { + w.buf = append(w.buf, p...) + for { + idx := bytes.IndexByte(w.buf, '\n') + if idx < 0 { + break + } + line := strings.TrimSpace(string(w.buf[:idx])) + w.buf = w.buf[idx+1:] + if line != "" { + w.emitter.log("[chrome] " + line) + } + } + return len(p), nil +} + // scriptStopError is thrown by stop() for a clean script exit with no error emitted. type scriptStopError struct{} @@ -484,8 +508,10 @@ func (r *Runner) Run(ctx context.Context) error { os.MkdirAll(filepath.Join(rootDir, "config"), 0755) //nolint:errcheck os.MkdirAll(filepath.Join(rootDir, "cache"), 0755) //nolint:errcheck + chromeLog := &chromeSterrWriter{emitter: emitter} l := launcher.New(). Headless(opts.Headless). + Logger(chromeLog). Set("disable-crash-reporter"). Set("crash-dumps-dir", crashDir). // Prevents navigator.webdriver from being set to true, which is @@ -497,6 +523,7 @@ func (r *Runner) Run(ctx context.Context) error { )...) if r.ExecPath != "" { + emitter.log(fmt.Sprintf("[session] using browser: %s", r.ExecPath)) l = l.Bin(r.ExecPath) } else { b := launcher.NewBrowser() @@ -508,6 +535,7 @@ func (r *Runner) Run(ctx context.Context) error { return goja.Undefined() } } + emitter.log(fmt.Sprintf("[session] using browser: %s", binPath)) l = l.Bin(binPath) } if opts.Proxy != "" {