Documentation
¶
Overview ¶
Package app 提供 twist 的核心业务逻辑:浏览器管理、CDP 连接、规则引擎和请求拦截。
Index ¶
- type Action
- type App
- type Browser
- type CDP
- func (c *CDP) AttachToTarget(ctx context.Context, targetID string) error
- func (c *CDP) Close() error
- func (c *CDP) CloseBrowser() error
- func (c *CDP) Connect(ctx context.Context) error
- func (c *CDP) DisableFetch(ctx context.Context) error
- func (c *CDP) EnableFetch(ctx context.Context) (fetch.RequestPausedClient, error)
- func (c *CDP) EnableNetwork(ctx context.Context) error
- func (c *CDP) ListTargets(ctx context.Context) ([]CDPTarget, error)
- func (c *CDP) NavigateTo(ctx context.Context, targetURL string) error
- func (c *CDP) NewTab(ctx context.Context, targetURL string) (*CDPTarget, error)
- func (c *CDP) TargetClient() *cdp.Client
- type CDPTarget
- type Condition
- type Config
- type Intercept
- type JSONPatch
- type Match
- type Options
- type Rule
- type Target
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Action ¶
type Action struct {
Type string `json:"type"`
Name string `json:"name,omitempty"`
Value any `json:"value,omitempty"`
Search string `json:"search,omitempty"`
Replace string `json:"replace,omitempty"`
ReplaceAll bool `json:"replaceAll,omitempty"`
StatusCode int `json:"statusCode,omitempty"`
Headers map[string]string `json:"headers,omitempty"`
Body string `json:"body,omitempty"`
BodyEncoding string `json:"bodyEncoding,omitempty"`
Encoding string `json:"encoding,omitempty"`
Patches []JSONPatch `json:"patches,omitempty"`
Selector string `json:"selector,omitempty"`
}
Action 执行行为,支持 18 种类型(请求/响应/通用)。
func (*Action) UnmarshalJSON ¶
type App ¶
type App struct {
// contains filtered or unexported fields
}
App 应用主结构,串联浏览器、CDP、规则引擎和拦截器的完整生命周期。
type Browser ¶
type Browser struct {
// contains filtered or unexported fields
}
Browser 管理浏览器进程的启动、端口检测和停止。
func NewBrowser ¶
func (*Browser) IsLaunched ¶
type CDP ¶
type CDP struct {
// contains filtered or unexported fields
}
CDP 管理浏览器和页面级 WebSocket 连接,封装 CDP 协议操作。 浏览器级连接用于管理标签页,页面级连接用于拦截具体页面。
func (*CDP) AttachToTarget ¶
AttachToTarget 连接到指定标签页的 WebSocket,建立页面级连接。
func (*CDP) CloseBrowser ¶
func (*CDP) EnableFetch ¶
func (*CDP) ListTargets ¶
ListTargets 通过 HTTP /json 端点获取所有可调试目标。
func (*CDP) TargetClient ¶
type CDPTarget ¶
type CDPTarget struct {
ID string `json:"id"`
Title string `json:"title"`
URL string `json:"url"`
Type string `json:"type"`
}
CDPTarget 浏览器标签页目标信息。
type Condition ¶
type Condition struct {
Type string `json:"type"`
Name string `json:"name,omitempty"`
Value string `json:"value,omitempty"`
Values []string `json:"values,omitempty"`
Pattern string `json:"pattern,omitempty"`
Path string `json:"path,omitempty"`
}
Condition 匹配条件,支持 25 种类型(URL/方法/Header/Query/Cookie/Body)。
func (*Condition) UnmarshalJSON ¶
type Config ¶
type Config struct {
ID string `json:"id"`
Name string `json:"name"`
Version string `json:"version"`
Description string `json:"description,omitempty"`
Settings map[string]any `json:"settings,omitempty"`
Rules []Rule `json:"rules"`
}
Config 规则配置文件根对象。
type Intercept ¶
type Intercept struct {
// contains filtered or unexported fields
}
Intercept 拦截引擎:Fetch 域事件循环、worker 池、规则匹配和 action 执行。
func NewIntercept ¶
type Options ¶
type Options struct {
Host string
Port int
Launch bool
LaunchBrowser string
LaunchArgs []string
URL string
ConfigFile string
ConfigData []byte
ListTargets bool
Target string
Verbose bool
Timeout int
}
Options 命令行解析后的运行参数。
type Rule ¶
type Rule struct {
ID string `json:"id"`
Name string `json:"name"`
Enabled bool `json:"enabled"`
Priority int `json:"priority"`
Stage string `json:"stage"`
Match Match `json:"match"`
Actions []Action `json:"actions"`
}
Rule 单条拦截规则,包含匹配条件和执行行为。
Click to show internal directories.
Click to hide internal directories.