Documentation
¶
Overview ¶
Package transport provides a shared network layer for fetching web content. It supports two levels: direct HTTP and browser-based (CDP).
Index ¶
- Constants
- type BrowserType
- type Config
- type PauseFunc
- type Transport
- func (t *Transport) BrowseEval(ctx context.Context, url string, js string) (any, error)
- func (t *Transport) BrowseEvalWithPause(ctx context.Context, url string, js string, pauseFn PauseFunc) (any, error)
- func (t *Transport) BrowseHTML(ctx context.Context, url string) (string, error)
- func (t *Transport) BrowseHTMLWithPause(ctx context.Context, url string, pauseFn PauseFunc) (string, error)
- func (t *Transport) BrowseInteractive(ctx context.Context, url string, pauseFn PauseFunc) error
- func (t *Transport) Close() error
- func (t *Transport) Do(ctx context.Context, req *http.Request) (*http.Response, error)
- func (t *Transport) GetHTML(ctx context.Context, url string) (string, error)
Constants ¶
const UserAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36"
UserAgent is a realistic Chrome User-Agent sent with all direct HTTP requests.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BrowserType ¶ added in v0.1.6
type BrowserType string
BrowserType identifies which browser backend to use.
const ( // BrowserChrome uses the system Chrome/Chromium (default). BrowserChrome BrowserType = "chrome" // BrowserLightpanda uses the Lightpanda headless browser. BrowserLightpanda BrowserType = "lightpanda" )
type Config ¶
type Config struct {
// WSURL is the remote CDP WebSocket URL. If empty, a local browser is launched.
WSURL string
// ProfileDir is the Chrome user data directory for persistent cookies/storage.
ProfileDir string
// Headless controls whether Chrome runs in headless mode (default: true).
Headless bool
// Browser selects the browser backend (default: "chrome").
Browser BrowserType
}
Config holds transport configuration.
type PauseFunc ¶ added in v0.1.5
PauseFunc is called after navigation to let the user interact with the browser (e.g. login, solve a CAPTCHA). It should block until the user is done. The context is cancelled if the parent context is cancelled.
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
Transport provides shared HTTP and browser-based network access.
func New ¶
New creates a new Transport with the given config. If the Lightpanda browser backend is selected, it downloads (if needed) and starts the Lightpanda server eagerly so errors surface immediately.
func (*Transport) BrowseEval ¶
BrowseEval navigates to a URL in a browser and evaluates JavaScript.
func (*Transport) BrowseEvalWithPause ¶ added in v0.1.5
func (t *Transport) BrowseEvalWithPause(ctx context.Context, url string, js string, pauseFn PauseFunc) (any, error)
BrowseEvalWithPause is like BrowseEval but calls pauseFn after navigation.
func (*Transport) BrowseHTML ¶
BrowseHTML navigates to a URL in a browser and returns the rendered HTML.
func (*Transport) BrowseHTMLWithPause ¶ added in v0.1.5
func (t *Transport) BrowseHTMLWithPause(ctx context.Context, url string, pauseFn PauseFunc) (string, error)
BrowseHTMLWithPause is like BrowseHTML but calls pauseFn after navigation.
func (*Transport) BrowseInteractive ¶ added in v0.1.5
BrowseInteractive navigates to a URL and keeps the browser open until pauseFn returns. This is used by the "login" command to let users interact with a site (login, solve CAPTCHAs) while cookies are persisted in the Chrome profile directory.