transport

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2026 License: MIT Imports: 10 Imported by: 0

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

This section is empty.

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

type PauseFunc func(ctx context.Context) error

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

func New(ctx context.Context, config Config) (*Transport, error)

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

func (t *Transport) BrowseEval(ctx context.Context, url string, js string) (any, error)

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

func (t *Transport) BrowseHTML(ctx context.Context, url string) (string, error)

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

func (t *Transport) BrowseInteractive(ctx context.Context, url string, pauseFn PauseFunc) error

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.

func (*Transport) Close

func (t *Transport) Close() error

Close releases resources held by the transport.

func (*Transport) Do

func (t *Transport) Do(ctx context.Context, req *http.Request) (*http.Response, error)

Do executes an HTTP request and returns the response. Caller is responsible for closing the response body.

func (*Transport) GetHTML

func (t *Transport) GetHTML(ctx context.Context, url string) (string, error)

GetHTML fetches a URL via direct HTTP and returns the response body as a string.

Jump to

Keyboard shortcuts

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