Documentation
¶
Index ¶
- Variables
- func FormatAccessibilityTree(nodes []*AXNode) string
- type AXNode
- type Box
- type Browser
- type BrowserContext
- func (c *BrowserContext) Browser() *Browser
- func (c *BrowserContext) ClearCookies() error
- func (c *BrowserContext) Close() error
- func (c *BrowserContext) Cookies() ([]Cookie, error)
- func (c *BrowserContext) LoadState(path string) error
- func (c *BrowserContext) NewPage() (*Page, error)
- func (c *BrowserContext) Pages() []*Page
- func (c *BrowserContext) SaveState(path string) error
- func (c *BrowserContext) SetCookies(cookies ...Cookie) error
- type BrowserState
- type ConsoleMessage
- type ContextOption
- func WithGeolocation(lat, lon float64) ContextOption
- func WithLocale(locale string) ContextOption
- func WithProxy(server string) ContextOption
- func WithProxyBypass(list string) ContextOption
- func WithState(path string) ContextOption
- func WithTimezone(tz string) ContextOption
- func WithUserAgent(ua string) ContextOption
- func WithViewport(width, height int) ContextOption
- type Cookie
- type Device
- type Dialog
- type Download
- type Element
- func (e *Element) Attribute(name string) (string, error)
- func (e *Element) BoundingBox() (*Box, error)
- func (e *Element) Check() error
- func (e *Element) Click() error
- func (e *Element) DoubleClick() error
- func (e *Element) Fill(text string) error
- func (e *Element) Focus() error
- func (e *Element) HTML() (string, error)
- func (e *Element) Hover() error
- func (e *Element) InnerText() (string, error)
- func (e *Element) IsVisible() (bool, error)
- func (e *Element) Press(key string) error
- func (e *Element) Screenshot(path string, opts ...ScreenshotOption) error
- func (e *Element) ScreenshotBytes(opts ...ScreenshotOption) ([]byte, error)
- func (e *Element) ScrollIntoView() error
- func (e *Element) SelectOption(value string) error
- func (e *Element) Text() (string, error)
- func (e *Element) Type(text string, opts ...TypeOption) error
- func (e *Element) Uncheck() error
- func (e *Element) Upload(paths ...string) error
- func (e *Element) WaitForHidden(opts ...WaitOption) error
- func (e *Element) WaitForVisible(opts ...WaitOption) error
- type ElementNotFoundError
- type EventType
- type Frame
- func (f *Frame) Click(selector string, opts ...WaitOption) error
- func (f *Frame) Evaluate(expression string) (any, error)
- func (f *Frame) Fill(selector, text string, opts ...WaitOption) error
- func (f *Frame) GetByAltText(text string, opts ...TextMatchOption) *Locator
- func (f *Frame) GetByLabel(text string, opts ...TextMatchOption) *Locator
- func (f *Frame) GetByPlaceholder(text string, opts ...TextMatchOption) *Locator
- func (f *Frame) GetByRole(role string, opts ...GetByRoleOption) *Locator
- func (f *Frame) GetByTestId(id string) *Locator
- func (f *Frame) GetByText(text string, opts ...TextMatchOption) *Locator
- func (f *Frame) GetByTitle(text string, opts ...TextMatchOption) *Locator
- func (f *Frame) ID() proto.FrameID
- func (f *Frame) Locator(selector string) *Locator
- func (f *Frame) Name() string
- func (f *Frame) Query(selector string) (*Element, error)
- func (f *Frame) QueryAll(selector string) ([]*Element, error)
- func (f *Frame) URL() string
- func (f *Frame) WaitSelector(selector string, opts ...WaitOption) (*Element, error)
- type GetByRoleOption
- type Keyboard
- type LaunchOption
- type Locator
- func (l *Locator) And(other *Locator) *Locator
- func (l *Locator) Attribute(name string) (string, error)
- func (l *Locator) BoundingBox() (*Box, error)
- func (l *Locator) Click(opts ...WaitOption) error
- func (l *Locator) Count() (int, error)
- func (l *Locator) Fill(text string, opts ...WaitOption) error
- func (l *Locator) Filter(f LocatorFilter) *Locator
- func (l *Locator) First() *Locator
- func (l *Locator) HTML() (string, error)
- func (l *Locator) InnerText() (string, error)
- func (l *Locator) IsVisible() (bool, error)
- func (l *Locator) Nth(n int) *Locator
- func (l *Locator) Or(other *Locator) *Locator
- func (l *Locator) Press(key string, opts ...WaitOption) error
- func (l *Locator) Screenshot(path string, opts ...ScreenshotOption) error
- func (l *Locator) Text() (string, error)
- func (l *Locator) Type(text string, opts ...TypeOption) error
- func (l *Locator) WaitFor(opts ...WaitOption) error
- type LocatorFilter
- type Mouse
- type NavigateOption
- type NavigateWait
- type NavigationError
- type Page
- func (p *Page) AccessibilityTree() ([]*AXNode, error)
- func (p *Page) AddInitScript(script string) error
- func (p *Page) BringToFront() error
- func (p *Page) Click(selector string, opts ...WaitOption) error
- func (p *Page) Close() error
- func (p *Page) Content() (string, error)
- func (p *Page) Context() *BrowserContext
- func (p *Page) Emulate(d Device) error
- func (p *Page) Evaluate(expression string) (any, error)
- func (p *Page) EvaluateHandle(expression string) (*Element, error)
- func (p *Page) EvaluateOn(el *Element, fn string, args ...any) (any, error)
- func (p *Page) ExposeFunction(name string, fn func(args []json.RawMessage) (any, error)) (func(), error)
- func (p *Page) Fill(selector, text string, opts ...WaitOption) error
- func (p *Page) Frame(nameOrID string) (*Frame, error)
- func (p *Page) Frames() ([]*Frame, error)
- func (p *Page) GetByAltText(text string, opts ...TextMatchOption) *Locator
- func (p *Page) GetByLabel(text string, opts ...TextMatchOption) *Locator
- func (p *Page) GetByPlaceholder(text string, opts ...TextMatchOption) *Locator
- func (p *Page) GetByRole(role string, opts ...GetByRoleOption) *Locator
- func (p *Page) GetByTestId(id string) *Locator
- func (p *Page) GetByText(text string, opts ...TextMatchOption) *Locator
- func (p *Page) GetByTitle(text string, opts ...TextMatchOption) *Locator
- func (p *Page) GoBack(opts ...NavigateOption) error
- func (p *Page) GoForward(opts ...NavigateOption) error
- func (p *Page) IsClosed() bool
- func (p *Page) Keyboard() *Keyboard
- func (p *Page) Locator(selector string) *Locator
- func (p *Page) Mouse() *Mouse
- func (p *Page) Navigate(url string, opts ...NavigateOption) error
- func (p *Page) On(event EventType, handler any) func()
- func (p *Page) OnConsole(fn func(*ConsoleMessage)) func()
- func (p *Page) OnDialog(fn func(*Dialog)) func()
- func (p *Page) OnRequest(fn func(*Request)) func()
- func (p *Page) OnResponse(fn func(*Response)) func()
- func (p *Page) PDF(path string) error
- func (p *Page) PDFBytes() ([]byte, error)
- func (p *Page) Press(selector, key string, opts ...WaitOption) error
- func (p *Page) Query(selector string) (*Element, error)
- func (p *Page) QueryAll(selector string) ([]*Element, error)
- func (p *Page) Reload(opts ...NavigateOption) error
- func (p *Page) Route(pattern string, handler func(*Route)) func()
- func (p *Page) Screenshot(path string, opts ...ScreenshotOption) error
- func (p *Page) ScreenshotBytes(opts ...ScreenshotOption) ([]byte, error)
- func (p *Page) SetContent(html string) error
- func (p *Page) SetExtraHTTPHeaders(headers map[string]string) error
- func (p *Page) SetOffline(offline bool) error
- func (p *Page) SetViewport(width, height int) error
- func (p *Page) Timeout(d time.Duration) *Page
- func (p *Page) Title() (string, error)
- func (p *Page) Type(selector, text string, opts ...TypeOption) error
- func (p *Page) URL() (string, error)
- func (p *Page) WaitForFunction(expression string, opts ...WaitOption) error
- func (p *Page) WaitForPopup(opts ...PopupOption) (*Page, error)
- func (p *Page) WaitForURL(pattern string, opts ...WaitOption) error
- func (p *Page) WaitNavigation(opts ...NavigateOption) error
- func (p *Page) WaitSelector(selector string, opts ...WaitOption) (*Element, error)
- func (p *Page) WithContext(ctx context.Context) *Page
- type Pool
- type PopupOption
- type Request
- type Response
- type Route
- type ScreenshotOption
- type TextMatchOption
- type TimeoutError
- type TypeOption
- type WaitOption
- type WaitVisibility
Constants ¶
This section is empty.
Variables ¶
var ( IPhone15 = Device{ Name: "iPhone 15", UserAgent: "Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1", ViewportWidth: 393, ViewportHeight: 852, DeviceScaleFactor: 3, IsMobile: true, HasTouch: true, } IPhone15ProMax = Device{ Name: "iPhone 15 Pro Max", UserAgent: "Mozilla/5.0 (iPhone; CPU iPhone OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1", ViewportWidth: 430, ViewportHeight: 932, DeviceScaleFactor: 3, IsMobile: true, HasTouch: true, } Pixel7 = Device{ Name: "Pixel 7", UserAgent: "Mozilla/5.0 (Linux; Android 13; Pixel 7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Mobile Safari/537.36", ViewportWidth: 412, ViewportHeight: 915, DeviceScaleFactor: 2.625, IsMobile: true, HasTouch: true, } Pixel8 = Device{ Name: "Pixel 8", UserAgent: "Mozilla/5.0 (Linux; Android 14; Pixel 8) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/119.0.0.0 Mobile Safari/537.36", ViewportWidth: 412, ViewportHeight: 915, DeviceScaleFactor: 2.625, IsMobile: true, HasTouch: true, } IPadPro11 = Device{ Name: "iPad Pro 11", UserAgent: "Mozilla/5.0 (iPad; CPU OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1", ViewportWidth: 834, ViewportHeight: 1194, DeviceScaleFactor: 2, IsMobile: true, HasTouch: true, } IPadAir = Device{ Name: "iPad Air", UserAgent: "Mozilla/5.0 (iPad; CPU OS 17_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.0 Mobile/15E148 Safari/604.1", ViewportWidth: 820, ViewportHeight: 1180, DeviceScaleFactor: 2, IsMobile: true, HasTouch: true, } GalaxyS23 = Device{ Name: "Galaxy S23", UserAgent: "Mozilla/5.0 (Linux; Android 13; SM-S911B) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Mobile Safari/537.36", ViewportWidth: 360, ViewportHeight: 780, DeviceScaleFactor: 3, IsMobile: true, HasTouch: true, } )
var ( ErrBrowserClosed = errors.New("bonk: browser closed") ErrContextClosed = errors.New("bonk: context closed") ErrPageClosed = errors.New("bonk: page closed") ErrSessionClosed = errors.New("bonk: session closed") ErrChromeNotFound = errors.New("bonk: chrome binary not found") ErrChromeStartup = errors.New("bonk: chrome failed to start") ErrStaleElement = errors.New("bonk: stale element reference") )
Functions ¶
func FormatAccessibilityTree ¶ added in v0.2.0
FormatAccessibilityTree formats the tree as indexed text for LLM consumption. Interactive elements get numbered indices; non-interactive elements are shown without indices.
Types ¶
type AXNode ¶ added in v0.2.0
type AXNode struct {
Role string
Name string
Value string
Disabled bool
Focused bool
Checked string
Selected bool
Expanded string
Level int
Children []*AXNode
}
AXNode represents a node in the accessibility tree.
type Browser ¶
type Browser struct {
// contains filtered or unexported fields
}
Browser represents a running Chrome instance.
func Connect ¶
func Connect(wsURL string, opts ...LaunchOption) (*Browser, error)
Connect attaches to an already-running Chrome instance.
func Launch ¶
func Launch(opts ...LaunchOption) (*Browser, error)
Launch starts a new Chrome browser process and connects to it.
func (*Browser) NewContext ¶
func (b *Browser) NewContext(opts ...ContextOption) (*BrowserContext, error)
NewContext creates a new isolated browser context.
func (*Browser) OnDisconnect ¶
func (b *Browser) OnDisconnect(fn func())
OnDisconnect registers a callback invoked when the WebSocket connection drops.
type BrowserContext ¶
type BrowserContext struct {
// contains filtered or unexported fields
}
BrowserContext represents an isolated browser context with its own cookies, cache, and storage.
func (*BrowserContext) Browser ¶
func (c *BrowserContext) Browser() *Browser
Browser returns the parent browser.
func (*BrowserContext) ClearCookies ¶
func (c *BrowserContext) ClearCookies() error
ClearCookies clears all cookies in the browser context.
func (*BrowserContext) Close ¶
func (c *BrowserContext) Close() error
Close disposes the browser context and all its pages.
func (*BrowserContext) Cookies ¶
func (c *BrowserContext) Cookies() ([]Cookie, error)
Cookies returns all cookies in the browser context. Requires at least one page to be open.
func (*BrowserContext) LoadState ¶
func (c *BrowserContext) LoadState(path string) error
LoadState restores browser context state from a file.
func (*BrowserContext) NewPage ¶
func (c *BrowserContext) NewPage() (*Page, error)
NewPage creates a new page (tab) in this browser context.
func (*BrowserContext) Pages ¶
func (c *BrowserContext) Pages() []*Page
Pages returns all open pages in this context.
func (*BrowserContext) SaveState ¶
func (c *BrowserContext) SaveState(path string) error
SaveState saves the browser context state (cookies, localStorage) to a file.
func (*BrowserContext) SetCookies ¶
func (c *BrowserContext) SetCookies(cookies ...Cookie) error
SetCookies sets cookies in the browser context.
type BrowserState ¶
type BrowserState struct {
Cookies []Cookie `json:"cookies"`
LocalStorage map[string]map[string]string `json:"localStorage,omitempty"`
}
BrowserState holds serializable browser state for persistence. Includes cookies and localStorage. IndexedDB is not supported.
type ConsoleMessage ¶
ConsoleMessage represents a console API call.
type ContextOption ¶
type ContextOption func(*contextConfig)
ContextOption configures a browser context.
func WithGeolocation ¶
func WithGeolocation(lat, lon float64) ContextOption
WithGeolocation sets the geolocation override.
func WithProxy ¶
func WithProxy(server string) ContextOption
WithProxy sets a proxy server for the context.
func WithProxyBypass ¶
func WithProxyBypass(list string) ContextOption
WithProxyBypass sets the proxy bypass list.
func WithState ¶
func WithState(path string) ContextOption
WithState loads browser state (cookies, localStorage) from a file.
func WithTimezone ¶
func WithTimezone(tz string) ContextOption
WithTimezone sets the timezone override.
func WithUserAgent ¶
func WithUserAgent(ua string) ContextOption
WithUserAgent sets the user agent string for the context.
func WithViewport ¶
func WithViewport(width, height int) ContextOption
WithViewport sets the default viewport size for new pages.
type Cookie ¶
type Cookie struct {
Name string `json:"name"`
Value string `json:"value"`
Domain string `json:"domain"`
Path string `json:"path"`
Expires float64 `json:"expires"`
HTTPOnly bool `json:"httpOnly"`
Secure bool `json:"secure"`
SameSite string `json:"sameSite"`
}
Cookie represents a browser cookie.
type Device ¶
type Device struct {
Name string
UserAgent string
ViewportWidth int
ViewportHeight int
DeviceScaleFactor float64
IsMobile bool
HasTouch bool
}
Device describes a device profile for emulation.
type Dialog ¶
type Dialog struct {
Type string
Message string
DefaultPrompt string
// contains filtered or unexported fields
}
Dialog represents a JavaScript dialog (alert, confirm, prompt).
type Download ¶
type Download struct {
// contains filtered or unexported fields
}
Download represents a file download.
func (*Download) SaveAs ¶
SaveAs copies the downloaded file to the given path. Blocks until the download completes.
func (*Download) SaveAsContext ¶
SaveAsContext copies the downloaded file to the given path, respecting the context for cancellation and deadlines.
func (*Download) SuggestedFilename ¶
SuggestedFilename returns the browser-suggested filename.
type Element ¶
type Element struct {
// contains filtered or unexported fields
}
Element represents a DOM element on a page.
func (*Element) BoundingBox ¶
BoundingBox returns the element's bounding box in viewport coordinates.
func (*Element) DoubleClick ¶
DoubleClick scrolls the element into view and double-clicks it.
func (*Element) Screenshot ¶
func (e *Element) Screenshot(path string, opts ...ScreenshotOption) error
Screenshot captures a screenshot of the element and saves it to the given path.
func (*Element) ScreenshotBytes ¶ added in v0.2.0
func (e *Element) ScreenshotBytes( opts ...ScreenshotOption, ) ([]byte, error)
ScreenshotBytes captures a screenshot of the element and returns PNG bytes.
func (*Element) ScrollIntoView ¶
ScrollIntoView scrolls the element into view.
func (*Element) SelectOption ¶
SelectOption selects an option in a <select> element by value.
func (*Element) Type ¶
func (e *Element) Type(text string, opts ...TypeOption) error
Type types the given text character by character with key events.
func (*Element) WaitForHidden ¶
func (e *Element) WaitForHidden(opts ...WaitOption) error
WaitForHidden waits until the element becomes hidden.
func (*Element) WaitForVisible ¶
func (e *Element) WaitForVisible(opts ...WaitOption) error
WaitForVisible waits until the element becomes visible.
type ElementNotFoundError ¶
type ElementNotFoundError struct {
Selector string
}
ElementNotFoundError is returned when a selector matches no elements.
func (*ElementNotFoundError) Error ¶
func (e *ElementNotFoundError) Error() string
type Frame ¶
type Frame struct {
// contains filtered or unexported fields
}
Frame represents an iframe within a page.
func (*Frame) Click ¶
func (f *Frame) Click(selector string, opts ...WaitOption) error
Click waits for the selector in this frame and clicks the element.
func (*Frame) Fill ¶
func (f *Frame) Fill(selector, text string, opts ...WaitOption) error
Fill waits for the selector in this frame and fills the input.
func (*Frame) GetByAltText ¶ added in v0.2.0
func (f *Frame) GetByAltText(text string, opts ...TextMatchOption) *Locator
GetByAltText returns a Locator matching elements by their alt attribute within the frame.
func (*Frame) GetByLabel ¶ added in v0.2.0
func (f *Frame) GetByLabel(text string, opts ...TextMatchOption) *Locator
GetByLabel returns a Locator matching form controls by their associated label text within the frame.
func (*Frame) GetByPlaceholder ¶ added in v0.2.0
func (f *Frame) GetByPlaceholder( text string, opts ...TextMatchOption, ) *Locator
GetByPlaceholder returns a Locator matching elements by their placeholder attribute within the frame.
func (*Frame) GetByRole ¶ added in v0.2.0
func (f *Frame) GetByRole(role string, opts ...GetByRoleOption) *Locator
GetByRole returns a Locator matching elements by ARIA role within the frame.
func (*Frame) GetByTestId ¶ added in v0.2.0
GetByTestId returns a Locator matching elements by their data-testid attribute within the frame.
func (*Frame) GetByText ¶ added in v0.2.0
func (f *Frame) GetByText(text string, opts ...TextMatchOption) *Locator
GetByText returns a Locator matching elements by their visible text content within the frame.
func (*Frame) GetByTitle ¶ added in v0.2.0
func (f *Frame) GetByTitle(text string, opts ...TextMatchOption) *Locator
GetByTitle returns a Locator matching elements by their title attribute within the frame.
func (*Frame) WaitSelector ¶
func (f *Frame) WaitSelector( selector string, opts ...WaitOption, ) (*Element, error)
WaitSelector waits for an element matching the selector within this frame.
type GetByRoleOption ¶ added in v0.2.0
type GetByRoleOption func(*getByRoleConfig)
GetByRoleOption configures GetByRole behavior.
func WithName ¶ added in v0.2.0
func WithName(name string, opts ...TextMatchOption) GetByRoleOption
WithName filters elements by their accessible name. Pass Exact() to require an exact name match.
type Keyboard ¶
type Keyboard struct {
// contains filtered or unexported fields
}
Keyboard provides low-level keyboard control on a page.
func (*Keyboard) InsertText ¶
InsertText inserts text without key events (instant).
type LaunchOption ¶
type LaunchOption func(*launchConfig)
LaunchOption configures browser launch behavior.
func Args ¶
func Args(args ...string) LaunchOption
Args appends additional command-line arguments to the Chrome launch.
func ChromePath ¶
func ChromePath(path string) LaunchOption
ChromePath sets an explicit path to the Chrome binary.
func Env ¶
func Env(env ...string) LaunchOption
Env appends additional environment variables for the Chrome process.
func Headless ¶
func Headless(v bool) LaunchOption
Headless controls whether Chrome runs in headless mode. Default is true.
func Stealth ¶
func Stealth(v bool) LaunchOption
Stealth enables anti-detection measures. Default is true. When enabled: disables automation-revealing Chrome flags, skips Runtime.enable (which is the primary CDP detection signal), injects JS patches to spoof navigator properties, and ensures Client Hints headers are consistent. Trade-off: OnConsole event handler won't work in stealth mode.
func UserDataDir ¶
func UserDataDir(path string) LaunchOption
UserDataDir sets the user data directory for Chrome. If empty, a temporary directory is created and cleaned up on Close.
func WithLogger ¶
func WithLogger(l *slog.Logger) LaunchOption
WithLogger enables debug logging of all CDP messages using the given logger.
type Locator ¶
type Locator struct {
// contains filtered or unexported fields
}
Locator is a Playwright-style selector handle that re-queries on every action. Locators never go stale because they don't cache a DOM reference.
func (*Locator) And ¶ added in v0.2.0
And returns a new Locator matching elements that satisfy both this locator and the other locator.
func (*Locator) BoundingBox ¶
BoundingBox returns the element's bounding box.
func (*Locator) Click ¶
func (l *Locator) Click(opts ...WaitOption) error
Click waits for the element and clicks it.
func (*Locator) Fill ¶
func (l *Locator) Fill(text string, opts ...WaitOption) error
Fill waits for the element and fills it with text.
func (*Locator) Filter ¶ added in v0.2.0
func (l *Locator) Filter(f LocatorFilter) *Locator
Filter returns a new Locator that narrows matches by the given criteria. All specified criteria must be satisfied (AND semantics).
func (*Locator) Or ¶ added in v0.2.0
Or returns a new Locator matching elements that satisfy either this locator or the other locator. Results are in document order.
func (*Locator) Press ¶
func (l *Locator) Press(key string, opts ...WaitOption) error
Press waits for the element and presses a key.
func (*Locator) Screenshot ¶
func (l *Locator) Screenshot(path string, opts ...ScreenshotOption) error
Screenshot captures a screenshot of the element.
func (*Locator) Type ¶
func (l *Locator) Type(text string, opts ...TypeOption) error
Type waits for the element and types text character by character.
func (*Locator) WaitFor ¶
func (l *Locator) WaitFor(opts ...WaitOption) error
WaitFor waits until the element is attached to the DOM.
type LocatorFilter ¶ added in v0.2.0
LocatorFilter specifies criteria for narrowing locator matches.
type Mouse ¶
type Mouse struct {
// contains filtered or unexported fields
}
Mouse provides low-level mouse control on a page.
type NavigateOption ¶
type NavigateOption func(*navigateConfig)
NavigateOption configures navigation behavior.
func WithTimeout ¶
func WithTimeout(d time.Duration) NavigateOption
WithTimeout sets the navigation timeout.
func WithWaitUntil ¶
func WithWaitUntil(w NavigateWait) NavigateOption
WithWaitUntil sets when navigation is considered complete.
type NavigateWait ¶
type NavigateWait int
NavigateWait specifies when navigation is considered complete.
const ( WaitLoad NavigateWait = iota WaitDOMContentLoaded WaitNetworkIdle )
type NavigationError ¶
type NavigationError struct {
}
NavigationError is returned when page navigation fails.
func (*NavigationError) Error ¶
func (e *NavigationError) Error() string
func (*NavigationError) Unwrap ¶
func (e *NavigationError) Unwrap() error
Unwrap returns the underlying cause.
type Page ¶
type Page struct {
// contains filtered or unexported fields
}
Page represents a single browser tab/page.
func (*Page) AccessibilityTree ¶ added in v0.2.0
AccessibilityTree returns the page's accessibility tree.
func (*Page) AddInitScript ¶
AddInitScript adds a script that will be evaluated on every new document created in the page, including iframes. Useful for injecting polyfills or overriding APIs before page scripts run.
func (*Page) BringToFront ¶
BringToFront activates this page (tab).
func (*Page) Click ¶
func (p *Page) Click(selector string, opts ...WaitOption) error
Click waits for the selector and clicks the element.
func (*Page) Context ¶
func (p *Page) Context() *BrowserContext
Context returns the parent browser context.
func (*Page) Emulate ¶
Emulate applies a device profile to the page, setting viewport, user agent, device scale factor, and touch emulation.
func (*Page) Evaluate ¶
Evaluate executes a JavaScript expression and returns the result as a Go value.
func (*Page) EvaluateHandle ¶
EvaluateHandle executes a JavaScript expression and returns the result as an Element handle (for non-primitive return values like DOM nodes).
func (*Page) EvaluateOn ¶
EvaluateOn executes a JavaScript function with the element as `this`. The function should be in the form "function(arg1, arg2) { ... }".
func (*Page) ExposeFunction ¶
func (p *Page) ExposeFunction( name string, fn func(args []json.RawMessage) (any, error), ) (func(), error)
ExposeFunction exposes a Go function to page JavaScript under the given name. The function receives a slice of arguments and returns a value or error. Page scripts can call the function as `window.<name>(args...)`.
func (*Page) Fill ¶
func (p *Page) Fill(selector, text string, opts ...WaitOption) error
Fill waits for the selector and fills the input with text.
func (*Page) GetByAltText ¶ added in v0.2.0
func (p *Page) GetByAltText(text string, opts ...TextMatchOption) *Locator
GetByAltText returns a Locator matching elements by their alt attribute.
func (*Page) GetByLabel ¶ added in v0.2.0
func (p *Page) GetByLabel(text string, opts ...TextMatchOption) *Locator
GetByLabel returns a Locator matching form controls by their associated label text. Checks <label> elements, aria-label, and aria-labelledby attributes.
func (*Page) GetByPlaceholder ¶ added in v0.2.0
func (p *Page) GetByPlaceholder(text string, opts ...TextMatchOption) *Locator
GetByPlaceholder returns a Locator matching elements by their placeholder attribute.
func (*Page) GetByRole ¶ added in v0.2.0
func (p *Page) GetByRole(role string, opts ...GetByRoleOption) *Locator
GetByRole returns a Locator matching elements by ARIA role. Matches both explicit role attributes and implicit roles from HTML semantics.
func (*Page) GetByTestId ¶ added in v0.2.0
GetByTestId returns a Locator matching elements by their data-testid attribute.
func (*Page) GetByText ¶ added in v0.2.0
func (p *Page) GetByText(text string, opts ...TextMatchOption) *Locator
GetByText returns a Locator matching elements by their visible text content.
func (*Page) GetByTitle ¶ added in v0.2.0
func (p *Page) GetByTitle(text string, opts ...TextMatchOption) *Locator
GetByTitle returns a Locator matching elements by their title attribute.
func (*Page) GoBack ¶
func (p *Page) GoBack(opts ...NavigateOption) error
GoBack navigates back in history and waits for completion.
func (*Page) GoForward ¶
func (p *Page) GoForward(opts ...NavigateOption) error
GoForward navigates forward in history and waits for completion.
func (*Page) Navigate ¶
func (p *Page) Navigate(url string, opts ...NavigateOption) error
Navigate navigates the page to the given URL and waits for completion.
func (*Page) On ¶
On registers a typed event handler. The handler type must match the event:
- Console → func(*ConsoleMessage)
- Dialog → func(*Dialog)
- Download → func(*Download)
func (*Page) OnConsole ¶
func (p *Page) OnConsole(fn func(*ConsoleMessage)) func()
OnConsole registers a handler for console messages.
func (*Page) OnRequest ¶
OnRequest registers a handler for intercepted requests. The handler can observe, modify headers, abort, or fulfill the request. If the handler doesn't call Continue, Abort, or Fulfill, the request is automatically continued.
func (*Page) OnResponse ¶
OnResponse registers a handler for intercepted responses. The handler can read the response body before it reaches the page. If the handler doesn't call Continue, the response is automatically continued.
func (*Page) PDFBytes ¶ added in v0.2.0
PDFBytes renders the page as a PDF and returns the raw bytes.
func (*Page) Press ¶
func (p *Page) Press(selector, key string, opts ...WaitOption) error
Press waits for the selector and presses a key.
func (*Page) Query ¶
Query finds the first element matching the CSS selector. Returns nil if no element matches.
func (*Page) Reload ¶
func (p *Page) Reload(opts ...NavigateOption) error
Reload reloads the current page and waits for completion.
func (*Page) Route ¶
Route intercepts requests matching the URL pattern. The handler receives a Route that can be fulfilled, continued, or aborted.
func (*Page) Screenshot ¶
func (p *Page) Screenshot(path string, opts ...ScreenshotOption) error
Screenshot captures a screenshot and saves it to the given path.
func (*Page) ScreenshotBytes ¶ added in v0.2.0
func (p *Page) ScreenshotBytes( opts ...ScreenshotOption, ) ([]byte, error)
ScreenshotBytes captures a screenshot and returns it as image bytes. Defaults to PNG unless AsJPEG is specified.
func (*Page) SetContent ¶
SetContent replaces the page's document HTML.
func (*Page) SetExtraHTTPHeaders ¶
SetExtraHTTPHeaders sets headers that will be sent with every request.
func (*Page) SetOffline ¶
SetOffline enables or disables offline emulation.
func (*Page) SetViewport ¶
SetViewport sets the page viewport dimensions.
func (*Page) Timeout ¶
Timeout returns a shallow copy of the Page with a context deadline set to the given duration from now.
func (*Page) Type ¶
func (p *Page) Type( selector, text string, opts ...TypeOption, ) error
Type waits for the selector and types text character by character.
func (*Page) WaitForFunction ¶
func (p *Page) WaitForFunction(expression string, opts ...WaitOption) error
WaitForFunction waits until the given JavaScript expression evaluates to a truthy value.
func (*Page) WaitForPopup ¶ added in v0.2.0
func (p *Page) WaitForPopup(opts ...PopupOption) (*Page, error)
WaitForPopup waits for a new page (tab/popup) to be opened by this page and returns it. The caller should trigger the popup after calling this method.
func (*Page) WaitForURL ¶
func (p *Page) WaitForURL(pattern string, opts ...WaitOption) error
WaitForURL waits until the page URL matches the given glob pattern.
func (*Page) WaitNavigation ¶
func (p *Page) WaitNavigation(opts ...NavigateOption) error
WaitNavigation waits for the next navigation to complete.
func (*Page) WaitSelector ¶
func (p *Page) WaitSelector( selector string, opts ...WaitOption, ) (*Element, error)
WaitSelector waits for an element matching the selector to appear. By default waits for the element to be attached to the DOM. Use WaitVisibleOption() to also require visibility, or WaitHiddenOption() to wait until the element is hidden or removed.
func (*Page) WithContext ¶
WithContext returns a shallow copy of the Page with the given context. All CDP calls made on the returned Page will respect the context's deadline and cancellation. The copy shares the underlying session, fetch manager, and mutex with the original.
type Pool ¶
type Pool struct {
// contains filtered or unexported fields
}
Pool manages a pool of reusable pages for concurrent automation.
type PopupOption ¶ added in v0.2.0
type PopupOption func(*popupConfig)
PopupOption configures WaitForPopup behavior.
func PopupTimeout ¶ added in v0.2.0
func PopupTimeout(d time.Duration) PopupOption
PopupTimeout sets the maximum time to wait for a popup.
type Request ¶
type Request struct {
URL string
Method string
Headers map[string]string
PostData string
ResourceType string
// contains filtered or unexported fields
}
Request represents an intercepted network request. Call Continue, Abort, or Fulfill to handle the request.
type Response ¶
type Response struct {
URL string
Status int64
Headers map[string]string
// contains filtered or unexported fields
}
Response represents an intercepted network response.
type Route ¶
type Route struct {
Request *Request
// contains filtered or unexported fields
}
Route represents a pattern-matched intercepted request.
type ScreenshotOption ¶
type ScreenshotOption func(*screenshotConfig)
ScreenshotOption configures screenshot behavior.
func AsJPEG ¶ added in v0.2.0
func AsJPEG() ScreenshotOption
AsJPEG captures the screenshot as JPEG instead of PNG. Quality defaults to 80 if not set via ScreenshotQuality.
func MaxWidth ¶ added in v0.2.0
func MaxWidth(px int) ScreenshotOption
MaxWidth sets the maximum width for the screenshot. If the captured image is wider, it is downscaled proportionally.
func ScreenshotQuality ¶
func ScreenshotQuality(q int) ScreenshotOption
ScreenshotQuality sets the JPEG/WebP quality (0-100).
type TextMatchOption ¶ added in v0.2.0
type TextMatchOption func(*textMatchConfig)
TextMatchOption configures text matching behavior for GetBy* methods.
func Exact ¶ added in v0.2.0
func Exact() TextMatchOption
Exact requires an exact text match instead of substring containment.
type TimeoutError ¶
TimeoutError is returned when an operation exceeds its deadline.
func (*TimeoutError) Error ¶
func (e *TimeoutError) Error() string
func (*TimeoutError) Unwrap ¶
func (e *TimeoutError) Unwrap() error
Unwrap returns the underlying cause.
type TypeOption ¶
type TypeOption func(*typeConfig)
TypeOption configures typing behavior.
func WaitFor ¶
func WaitFor(opts ...WaitOption) TypeOption
WaitFor adds wait options that apply when page.Type() waits for the selector.
func WithDelay ¶
func WithDelay(d time.Duration) TypeOption
WithDelay sets the delay between keystrokes.
type WaitOption ¶
type WaitOption func(*waitConfig)
WaitOption configures wait behavior.
func WaitHiddenOption ¶
func WaitHiddenOption() WaitOption
WaitHiddenOption sets WaitSelector to wait until the element is hidden or removed.
func WaitInterval ¶
func WaitInterval(d time.Duration) WaitOption
WaitInterval sets the initial polling interval.
func WaitTimeout ¶
func WaitTimeout(d time.Duration) WaitOption
WaitTimeout sets the maximum time to wait.
func WaitVisibleOption ¶
func WaitVisibleOption() WaitOption
WaitVisibleOption sets the visibility condition for WaitSelector.
type WaitVisibility ¶
type WaitVisibility int
WaitVisibility specifies what state to wait for.
const ( WaitAttached WaitVisibility = iota WaitUntilVisible WaitUntilHidden )
Source Files
¶
- browser.go
- context.go
- context_options.go
- cookie.go
- device.go
- element.go
- element_input.go
- element_query.go
- errors.go
- events.go
- frame.go
- getby.go
- getby_expr.go
- getby_options.go
- keyboard.go
- launch.go
- launch_options.go
- locator.go
- locator_filter.go
- match.go
- mouse.go
- network.go
- page.go
- page_accessibility.go
- page_eval.go
- page_input.go
- page_navigate.go
- page_popup.go
- page_screenshot.go
- pool.go
- request.go
- response.go
- route.go
- selector.go
- state.go
- stealth.go
- stealth_patches.go
- wait.go