Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ This pattern is useful in CI — run Rodney as a post-deploy check, an accessibi
|---|---|---|
| `RODNEY_HOME` | `~/.rodney` | Data directory for state and Chrome profile |
| `ROD_CHROME_BIN` | `/usr/bin/google-chrome` | Path to Chrome/Chromium binary |
| `ROD_CHROME_ARGS` | (none) | Extra Chrome flags as space-separated args (for example `disable-features=HttpsUpgrades`) |
| `ROD_TIMEOUT` | `30` | Default timeout in seconds for element queries |
| `HTTPS_PROXY` / `HTTP_PROXY` | (none) | Authenticated proxy auto-detected on start |

Expand Down
3 changes: 3 additions & 0 deletions help.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ current directory, the local session is used; otherwise the global session.
Use "rodney start --local" to create a directory-scoped session.

Environment:
ROD_CHROME_BIN Path to Chrome/Chromium binary
ROD_CHROME_ARGS Extra Chrome flags (space-separated)
ROD_TIMEOUT Default element query timeout in seconds
RODNEY_HOME Override data directory (default: ~/.rodney)

Exit codes:
Expand Down
70 changes: 63 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/go-rod/rod"
"github.com/go-rod/rod/lib/launcher"
"github.com/go-rod/rod/lib/launcher/flags"
"github.com/go-rod/rod/lib/proto"
)

Expand Down Expand Up @@ -78,12 +79,12 @@ func resolveStateDir(mode scopeMode, workingDir string) string {

// State persisted between CLI invocations
type State struct {
DebugURL string `json:"debug_url"`
ChromePID int `json:"chrome_pid"`
ActivePage int `json:"active_page"` // index into pages list
DataDir string `json:"data_dir"`
ProxyPID int `json:"proxy_pid,omitempty"` // PID of auth proxy helper
ProxyPort int `json:"proxy_port,omitempty"` // local port of auth proxy
DebugURL string `json:"debug_url"`
ChromePID int `json:"chrome_pid"`
ActivePage int `json:"active_page"` // index into pages list
DataDir string `json:"data_dir"`
ProxyPID int `json:"proxy_pid,omitempty"` // PID of auth proxy helper
ProxyPort int `json:"proxy_port,omitempty"` // local port of auth proxy
}

func stateDir() string {
Expand Down Expand Up @@ -294,6 +295,55 @@ func init() {
}
}

type chromeArg struct {
name string
value string
hasValue bool
}

func parseChromeArgs(raw string) ([]chromeArg, error) {
fields := strings.Fields(raw)
parsed := make([]chromeArg, 0, len(fields))

for _, field := range fields {
arg := strings.TrimLeft(field, "-")
if arg == "" {
return nil, fmt.Errorf("invalid flag %q", field)
}

parts := strings.SplitN(arg, "=", 2)
if parts[0] == "" {
return nil, fmt.Errorf("missing flag name in %q", field)
}

entry := chromeArg{name: parts[0]}
if len(parts) == 2 {
entry.value = parts[1]
entry.hasValue = true
}
parsed = append(parsed, entry)
}

return parsed, nil
}

func applyChromeArgs(l *launcher.Launcher, raw string) error {
args, err := parseChromeArgs(raw)
if err != nil {
return err
}

for _, arg := range args {
if arg.hasValue {
l.Set(flags.Flag(arg.name), arg.value)
continue
}
l.Set(flags.Flag(arg.name))
}

return nil
}

// withPage loads state, connects, and returns the active page.
// Caller should NOT close the browser (we just disconnect).
func withPage() (*State, *rod.Browser, *rod.Page) {
Expand Down Expand Up @@ -366,6 +416,12 @@ func cmdStart(args []string) {
l = l.Bin(bin)
}

if chromeArgs := os.Getenv("ROD_CHROME_ARGS"); chromeArgs != "" {
if err := applyChromeArgs(l, chromeArgs); err != nil {
fatal("invalid ROD_CHROME_ARGS: %v", err)
}
}

// Detect authenticated proxy and launch helper if needed
var proxyPID, proxyPort int
if server, user, pass, needed := detectProxy(); needed {
Expand Down Expand Up @@ -1515,7 +1571,7 @@ func queryAXNodes(page *rod.Page, name, role string) ([]*proto.AccessibilityAXNo
}

result, err := proto.AccessibilityQueryAXTree{
BackendNodeID: doc.Root.BackendNodeID,
BackendNodeID: doc.Root.BackendNodeID,
AccessibleName: name,
Role: role,
}.Call(page)
Expand Down
34 changes: 34 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"net/http/httptest"
"os"
"path/filepath"
"reflect"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -160,6 +161,39 @@ func navigateTo(t *testing.T, path string) *rod.Page {
return page
}

func TestParseChromeArgs_ParsesFlagsAndValues(t *testing.T) {
args, err := parseChromeArgs("disable-features=HttpsUpgrades --ignore-certificate-errors")
if err != nil {
t.Fatalf("parseChromeArgs returned error: %v", err)
}

want := []chromeArg{
{name: "disable-features", value: "HttpsUpgrades", hasValue: true},
{name: "ignore-certificate-errors", hasValue: false},
}

if !reflect.DeepEqual(args, want) {
t.Fatalf("unexpected parse result\nwant: %#v\ngot: %#v", want, args)
}
}

func TestParseChromeArgs_HandlesEmptyInput(t *testing.T) {
args, err := parseChromeArgs("")
if err != nil {
t.Fatalf("parseChromeArgs returned error: %v", err)
}
if len(args) != 0 {
t.Fatalf("expected empty args, got: %#v", args)
}
}

func TestParseChromeArgs_RejectsInvalidFlag(t *testing.T) {
_, err := parseChromeArgs("--")
if err == nil {
t.Fatal("expected parseChromeArgs to fail for invalid flag")
}
}

// =====================
// ax-tree tests (RED)
// =====================
Expand Down