browser

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 16, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package browser holds the connection-layer logic for reaching Chrome over CDP: the DevToolsActivePort reader (Path B) and the connection-ladder decision. It is deliberately free of chromedp so it unit-tests without a live browser.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CandidatePortFiles

func CandidatePortFiles() []string

CandidatePortFiles returns the OS-specific locations Chrome writes DevToolsActivePort to (Chrome family), first match wins. Overridable by the caller via CHROME_CDP_PORT_FILE.

func EndpointKey

func EndpointKey(portFile string, port int) string

EndpointKey identifies the debug endpoint a command targets, so the daemon socket and sticky state are keyed to the actual Chrome instance rather than a fixed port. An explicit --port wins (distinct ports get distinct keys); otherwise the key comes from the discovered DevToolsActivePort file, falling back to "default".

func FindPortFile

func FindPortFile(override string) string

FindPortFile returns the DevToolsActivePort path to use: an explicit override, else $CHROME_CDP_PORT_FILE, else the first existing OS candidate ("" if none).

func HostPort

func HostPort(wsURL string) (string, bool)

HostPort extracts the host:port authority from a ws:// URL.

func ParseDevToolsActivePort

func ParseDevToolsActivePort(content []byte) (port int, wsPath string, err error)

ParseDevToolsActivePort parses the two-line DevToolsActivePort file (line 1 = port, line 2 = the browser-level ws path).

func WSURLFromPortFile

func WSURLFromPortFile(path string) (string, error)

WSURLFromPortFile reads a DevToolsActivePort file and returns the literal browser-level WebSocket URL to hand to chromedp.NewRemoteAllocator.

Types

type Action

type Action int

Action is the connection-ladder outcome for a given Probe.

const (
	Attach           Action = iota // attach to Probe.PortFileWS (Path B)
	Launch                         // launch a managed Chrome (Path A fallback)
	InstructToggle                 // Chrome is running but not debug-enabled — guide chrome://inspect
	InstructNoLaunch               // nothing debug-enabled and --no-launch — print the launch command
)

func DecideConnection

func DecideConnection(p Probe) Action

DecideConnection walks the connection ladder:

  1. reachable debug endpoint -> Attach (Path B)
  2. no reachable endpoint, Chrome up -> InstructToggle (use the running session; never shadow it)
  3. no reachable endpoint, no Chrome -> Launch (Path A) unless --no-launch
  4. ...with --no-launch -> InstructNoLaunch

func (Action) String

func (a Action) String() string

type Probe

type Probe struct {
	PortFileWS    string // ws:// from DevToolsActivePort, or "" if unavailable
	WSReachable   bool   // did a WS connect to PortFileWS succeed?
	ChromeRunning bool   // is a Chrome process running (possibly without debug)?
	NoLaunch      bool   // the --no-launch flag
}

Probe captures the observable connection state the ladder decides on.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL