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 ¶
- Constants
- func EmbeddedTapWebSkillFS() fs.FS
- 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 ¶
const ( EmbeddedTapWebSkillRoot = "skills/tap-web" EmbeddedTapWebSkillConfig = EmbeddedTapWebSkillRoot + "/SKILL.md" )
Variables ¶
This section is empty.
Functions ¶
func EmbeddedTapWebSkillFS ¶ added in v0.4.1
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. |