browser

package
v0.29.1 Latest Latest
Warning

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

Go to latest
Published: Apr 7, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ActivateTab

func ActivateTab(debugURL string, targetID string) error

func ClickChromeElement

func ClickChromeElement(debugURL string, targetURL string, selector string, waitForNavigation bool) error

func CloseTab

func CloseTab(debugURL string, targetID string) error

func CloseTerminalWindow

func CloseTerminalWindow(cmd *exec.Cmd) error

CloseTerminalWindow attempts to close terminal windows for a given process Note: This is a best-effort attempt. macOS terminals launched via AppleScript may not always close cleanly as they detach from the parent process.

func GetChromeDebugURL

func GetChromeDebugURL(profileDir string) (string, error)

GetChromeDebugURL reads the DevTools WebSocket URL from Chrome's profile directory Chrome writes this information to DevToolsActivePort file when launched with --remote-debugging-port

func GetSPKIFingerprint

func GetSPKIFingerprint(certPath string) (string, error)

GetSPKIFingerprint calculates the SHA-256 SPKI fingerprint of a certificate This is used by Chrome to ignore certificate errors for our CA

func GoBack

func GoBack(debugURL string, targetID string) error

func GoForward

func GoForward(debugURL string, targetID string) error

func LaunchBrowser

func LaunchBrowser(browserType string, proxyAddress string, customCertPath string, profileDir string, startURL string) (*exec.Cmd, error)

func OpenChromeTab

func OpenChromeTab(debugURL string, url string) (string, error)

func ReloadTab

func ReloadTab(debugURL string, targetID string, bypassCache bool) error

func TakeChromeScreenshot

func TakeChromeScreenshot(debugURL string, targetID string, fullPage bool) ([]byte, error)

Types

type ChromeRemote

type ChromeRemote struct {
	// contains filtered or unexported fields
}

ChromeRemote manages a connection to a Chrome instance via DevTools Protocol

func NewChromeRemote

func NewChromeRemote(debugURL string) (*ChromeRemote, error)

NewChromeRemote creates a new ChromeRemote instance connected to the given debug URL

func (*ChromeRemote) ActivateTab

func (cr *ChromeRemote) ActivateTab(targetID string) error

ActivateTab switches focus to a specific tab

func (*ChromeRemote) ClickElement

func (cr *ChromeRemote) ClickElement(targetID string, targetURL string, selector string, waitForNavigation bool) error

ClickElement clicks an element on the page using Chrome DevTools Protocol. targetID can be empty to pick the best tab.

func (*ChromeRemote) Close

func (cr *ChromeRemote) Close()

Close closes the connection to Chrome and all sub-contexts

func (*ChromeRemote) CloseTab

func (cr *ChromeRemote) CloseTab(targetID string) error

CloseTab closes a specific tab

func (*ChromeRemote) CloseTargetContext

func (cr *ChromeRemote) CloseTargetContext(targetID string)

CloseTargetContext manually closes and removes a context from the cache

func (*ChromeRemote) DebugURL

func (cr *ChromeRemote) DebugURL() string

DebugURL returns the Chrome remote debugging WebSocket URL.

func (*ChromeRemote) Evaluate

func (cr *ChromeRemote) Evaluate(targetID string, jsExpr string, dest interface{}, timeoutMs int) error

Evaluate runs a JavaScript expression in the context of the given tab and unmarshals the result into dest (same semantics as chromedp.Evaluate). timeoutMs controls the per-call timeout; 0 uses a 15 s default.

func (*ChromeRemote) GetElements

func (cr *ChromeRemote) GetElements(targetID string, targetURL string) ([]ElementInfo, error)

GetElements extracts information about clickable elements on the page. targetID can be empty to pick the best tab.

func (*ChromeRemote) GoBack

func (cr *ChromeRemote) GoBack(targetID string) error

GoBack navigates back in browser history

func (*ChromeRemote) GoForward

func (cr *ChromeRemote) GoForward(targetID string) error

GoForward navigates forward in browser history

func (*ChromeRemote) ListTabs

func (cr *ChromeRemote) ListTabs() ([]TabInfo, error)

ListTabs lists all open tabs in Chrome

func (*ChromeRemote) Navigate

func (cr *ChromeRemote) Navigate(targetID string, url string, waitUntil string, timeoutMs int) (*NavigationResult, error)

Navigate navigates a specific tab to a URL

func (*ChromeRemote) OpenTab

func (cr *ChromeRemote) OpenTab(url string) (string, error)

OpenTab opens a new tab and returns its target ID. URL is optional.

func (*ChromeRemote) ReloadTab

func (cr *ChromeRemote) ReloadTab(targetID string, bypassCache bool) error

ReloadTab reloads a specific tab

func (*ChromeRemote) TakeScreenshot

func (cr *ChromeRemote) TakeScreenshot(targetID string, fullPage bool) ([]byte, error)

TakeScreenshot captures a screenshot of a specific tab (targetID). If targetID == "", it will try to pick a "best" tab (heuristic).

func (*ChromeRemote) TypeText added in v0.28.0

func (cr *ChromeRemote) TypeText(targetID string, selector string, text string, clearFirst bool, timeoutMs int) error

TypeText types text into an element identified by a CSS selector using CDP. It clicks the element first to focus it, clears any existing value, then types the text.

func (*ChromeRemote) WaitForSelector added in v0.28.0

func (cr *ChromeRemote) WaitForSelector(targetID string, selector string, timeoutMs int) error

WaitForSelector waits for a CSS selector to become visible on the page.

type ElementInfo

type ElementInfo struct {
	Selector    string `json:"selector"`    // CSS selector to use for clicking
	TagName     string `json:"tagName"`     // HTML tag name (e.g., "button", "a", "input")
	ID          string `json:"id"`          // Element ID attribute (if present)
	Class       string `json:"class"`       // Element class attribute (if present)
	Text        string `json:"text"`        // Visible text content
	Type        string `json:"type"`        // Input type or button type (if applicable)
	Href        string `json:"href"`        // Link href (for anchor tags)
	Name        string `json:"name"`        // Name attribute (if present)
	Aria        string `json:"aria"`        // ARIA label (if present)
	Placeholder string `json:"placeholder"` // Placeholder text (for inputs)
}

ElementInfo represents information about a clickable element on the page

func GetChromeElements

func GetChromeElements(debugURL string, targetURL string) ([]ElementInfo, error)
type NavigationResult struct {
	FinalURL     string `json:"finalUrl"`
	Status       string `json:"status"` // "success", "timeout", "error"
	NavigationID string `json:"navigationId"`
}

NavigationResult contains the result of a navigation operation

func NavigateToUrl(debugURL string, targetID string, url string, waitUntil string, timeoutMs int) (*NavigationResult, error)

type TabInfo

type TabInfo struct {
	ID          string `json:"id"`          // Target ID
	Title       string `json:"title"`       // Page title
	URL         string `json:"url"`         // Current URL
	Type        string `json:"type"`        // Target type (usually "page")
	Description string `json:"description"` // Description
}

TabInfo represents information about a Chrome tab

func ListChromeTabs

func ListChromeTabs(debugURL string) ([]TabInfo, error)

Jump to

Keyboard shortcuts

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