mirror of
https://github.com/phishingclub/phishingclub.git
synced 2026-06-08 07:33:52 +02:00
Merge branch 'feat-remote-browser' into test-build
This commit is contained in:
@@ -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 != "" {
|
||||
|
||||
Reference in New Issue
Block a user