transport

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: MIT Imports: 9 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 Config

type Config struct {
	// WSURL is the remote CDP WebSocket URL. If empty, a local Chrome 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
}

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(config Config) *Transport

New creates a new Transport with the given config.

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