Documentation
ΒΆ
Overview ΒΆ
Package tap provides a unified API for interacting with web pages.
Tap can run site scripts (with QuickJS β Browser fallback) and fetch clean content from URLs via go-defuddle. Both share a common transport layer for HTTP and browser-based network access.
Basic usage:
client, err := tap.New(ctx, tap.WithSitesDir("./sites"))
if err != nil {
log.Fatal(err)
}
defer client.Close()
// Run a site script
result, err := client.RunScript(ctx, "v2ex/hot", nil)
// Fetch clean content
content, err := client.Fetch(ctx, "https://example.com", nil)
Index ΒΆ
- type Client
- func (c *Client) Close() error
- func (c *Client) Fetch(ctx context.Context, url string, opts *fetch.Options) (*fetch.Result, error)
- func (c *Client) GetScript(name string) (*script.Script, bool)
- func (c *Client) ListScripts() []*script.Script
- func (c *Client) ListScriptsLocalOnly() []*script.Script
- func (c *Client) Login(ctx context.Context, url string, pauseFn transport.PauseFunc) error
- func (c *Client) RunScript(ctx context.Context, name string, args map[string]string) (any, error)
- type Option
- func WithBrowserType(bt transport.BrowserType) Option
- func WithForceBrowser(force bool) Option
- func WithHeadless(headless bool) Option
- func WithLocalOverrideDir(dir string) Option
- func WithPause(fn transport.PauseFunc) Option
- func WithProfileDir(dir string) Option
- func WithSitesDir(dir string) Option
- func WithTimeout(d time.Duration) Option
- func WithWSURL(url string) Option
- type ScriptNotFoundError
Constants ΒΆ
This section is empty.
Variables ΒΆ
This section is empty.
Functions ΒΆ
This section is empty.
Types ΒΆ
type Client ΒΆ
type Client struct {
// contains filtered or unexported fields
}
Client is the main entry point for the tap library.
func New ΒΆ
New creates a new Client with the given options. The context is used for any startup work (e.g. downloading a browser binary).
func (*Client) ListScripts ΒΆ
ListScripts returns all available scripts sorted by name.
func (*Client) ListScriptsLocalOnly ΒΆ added in v0.3.0
ListScriptsLocalOnly returns only scripts loaded from the local override directory.
type Option ΒΆ
type Option func(*options)
Option configures a Client.
func WithBrowserType ΒΆ added in v0.1.6
func WithBrowserType(bt transport.BrowserType) Option
WithBrowserType selects the browser backend ("chrome" or "lightpanda").
func WithForceBrowser ΒΆ added in v0.1.1
WithForceBrowser skips QuickJS and runs scripts directly in Chrome.
func WithHeadless ΒΆ added in v0.1.1
WithHeadless sets whether Chrome runs in headless mode (default: true).
func WithLocalOverrideDir ΒΆ added in v0.3.0
WithLocalOverrideDir sets a directory that is checked before the main sites cache. Scripts found here shadow cached versions and are flagged as local overrides. Mirrors the path structure: {dir}/{site}/{script}.js
func WithPause ΒΆ added in v0.1.5
WithPause sets a function that is called after browser navigation, allowing the user to interact (login, solve CAPTCHAs) before script execution.
func WithProfileDir ΒΆ
WithProfileDir sets the Chrome user data directory for persistent cookies/storage. Defaults to ~/.cache/tap/chrome-profile-$USER.
func WithSitesDir ΒΆ
WithSitesDir sets the directory containing site scripts.
func WithTimeout ΒΆ added in v0.1.1
WithTimeout sets the execution timeout for scripts and fetches.
type ScriptNotFoundError ΒΆ added in v0.1.1
ScriptNotFoundError is returned when a script name doesn't match any registered script.
func (*ScriptNotFoundError) Error ΒΆ added in v0.1.1
func (e *ScriptNotFoundError) Error() string
func (*ScriptNotFoundError) Suggestions ΒΆ added in v0.1.1
func (e *ScriptNotFoundError) Suggestions(max int) []string
Suggestions returns script names similar to the requested name, ranked by relevance.
Directories
ΒΆ
| Path | Synopsis |
|---|---|
|
Package browser defines the persistent browser session metadata model used by the planned `tap browser ...` workflow.
|
Package browser defines the persistent browser session metadata model used by the planned `tap browser ...` workflow. |
|
cmd
|
|
|
tap
command
|
|
|
Package engine provides execution engines for running site scripts.
|
Package engine provides execution engines for running site scripts. |
|
Package fetch provides URL content extraction using go-defuddle.
|
Package fetch provides URL content extraction using go-defuddle. |
|
Package script handles parsing and discovery of site scripts.
|
Package script handles parsing and discovery of site scripts. |
|
Package transport provides a shared network layer for fetching web content.
|
Package transport provides a shared network layer for fetching web content. |