Merge branch 'feat-remote-browser' into test-build

This commit is contained in:
Ronni Skansing
2026-05-17 19:48:06 +02:00
+28
View File
@@ -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 != "" {