Documentation
¶
Index ¶
- func InterpreterHash(source []byte) string
- type BotGuardMetric
- type Challenge
- type Options
- type Pointer
- type Profile
- type Runtime
- func (runtime *Runtime) Activate(ctx context.Context) error
- func (runtime *Runtime) Close()
- func (runtime *Runtime) Proof(ctx context.Context, digest string, prompt string) (string, error)
- func (runtime *Runtime) RefreshSnapshot(ctx context.Context) (string, error)
- func (runtime *Runtime) Replaced(ctx context.Context) error
- func (runtime *Runtime) RerunProof(ctx context.Context, digest string, rounds int) (string, error)
- func (runtime *Runtime) RunProof(ctx context.Context, digest string, prompt string) (string, error)
- func (runtime *Runtime) Settle(ctx context.Context) error
- func (runtime *Runtime) SubmitProof(ctx context.Context, digest string, result string, rounds int) (string, error)
- func (runtime *Runtime) TakeMetrics(ctx context.Context) ([]BotGuardMetric, error)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InterpreterHash ¶
InterpreterHash 返回解释器源码的 SHA-256 base64url 摘要
Types ¶
type BotGuardMetric ¶ added in v0.3.8
BotGuardMetric 是官网 BotGuard 包装层记录的一条 client streamz 指标,Metric 为 ec 或 cec 时 Value 是计数增量,其余为分布取值
type Challenge ¶
type Challenge struct {
MessageID string
InterpreterJavaScript string
InterpreterURL string
InterpreterHash string
Program string
GlobalName string
ClientExperimentsStateBlob string
// Packed 表示 challenge 来自响应第 2 字段的混淆字节,官网包装层为它记录解码耗时
Packed bool
}
Challenge 保存 Waa/Create 返回的客户端解释器输入
func ParseChallenge ¶
ParseChallenge 解析 Waa/Create 响应,第 2 字段的混淆 challenge 为空时读取第 1 字段的明文 challenge
type Options ¶
type Options struct {
Challenge Challenge
Interpreter string
Profile Profile
LoadImage func(string) bool
// LoadFrame 以浏览器 iframe 导航形状载入地址,返回是否收到文档响应
LoadFrame func(string) bool
// Pointer 是页面上可信指针与焦点所在的位置,同一页面先后新建的 VM 共用;为 nil 时按刚载入的页面
Pointer *Pointer
}
Options 定义一份 BotGuard VM 的解释器、宿主现场与网络依赖
type Pointer ¶ added in v0.3.8
type Pointer struct {
// contains filtered or unexported fields
}
Pointer 是页面上可信指针与焦点所在的位置
func NewPointer ¶ added in v0.3.8
func NewPointer() *Pointer
NewPointer 返回刚载入的页面上的位置:指针还没进入页面,焦点在提示词输入框
type Profile ¶
type Profile struct {
PageURL string
Locale string
TimeZone string
Window map[string]any
Screen map[string]any
Document map[string]any
Globals map[string]any
LocalStorage map[string]string
HasFocus bool
// TrustedTypes 表示页面 CSP 要求脚本注入点使用 Trusted Types
TrustedTypes bool
NavigationStart time.Time
Navigation map[string]any
// DOMLoading 是顶层页面旧版 performance.timing.domLoading 相对导航开始的毫秒数
DOMLoading int
// MediaInputs 是页面未授权时 enumerateDevices 列出的输入设备种类,按 audioinput、videoinput 顺序
MediaInputs []string
}
Profile 保存账户指纹与页面状态决定的宿主现场值
type Runtime ¶
type Runtime struct {
// contains filtered or unexported fields
}
Runtime 在嵌入的 SpiderMonkey 中持有一份与官网页面同形态的 BotGuard 生命周期
func NewRuntime ¶
NewRuntime 在 Firefox 宿主中加载解释器并初始化 challenge program
func (*Runtime) Activate ¶ added in v0.3.8
Activate 记录一次用户点击或按键:此后 navigator.userActivation 的 hasBeenActive 为 true,5 秒内 isActive 为 true
func (*Runtime) RefreshSnapshot ¶
RefreshSnapshot 生成官网刷新 Waa/Create 时携带的无绑定 snapshot
func (*Runtime) Replaced ¶ added in v0.3.8
Replaced 在页面替换指针下的元素时派发 Firefox 的 pointerover 与 mouseover:点击 Run 后按钮切换为 Stop 与切换回 Run,点击 Rerun 后最后一轮被移除,提交函数结果后函数调用块被替换;指针不在这三处时不派发
func (*Runtime) RerunProof ¶ added in v0.3.8
RerunProof 在 rounds 轮的对话上点击最后一轮的 Rerun 后为 SHA-256 digest 生成 fresh proof,与官网 Rerun 一样不写入提示词
func (*Runtime) RunProof ¶ added in v0.3.0
RunProof 以可信键盘把文本粘贴进页面提示词输入框(输入框没有焦点时先以可信指针点击它)并点击 Run 后为 SHA-256 digest 生成 fresh proof,与官网用户粘贴提示词、点击 Run 后页面为 GenerateContent 取 proof 的顺序相同,返回前清空输入框
func (*Runtime) SubmitProof ¶ added in v0.3.9
func (runtime *Runtime) SubmitProof(ctx context.Context, digest string, result string, rounds int) (string, error)
SubmitProof 在 rounds 轮的对话上以可信指针点击最后一轮函数调用块中的函数响应输入框、以可信键盘粘贴 result,再点击提交后为 SHA-256 digest 生成 fresh proof,与官网用户提交函数结果后页面为 GenerateContent 取 proof 的顺序相同
func (*Runtime) TakeMetrics ¶ added in v0.3.8
func (runtime *Runtime) TakeMetrics(ctx context.Context) ([]BotGuardMetric, error)
TakeMetrics 在事件循环中取出上次以来记录的 BotGuard 指标,排在已排队的任务之后执行,与官网包装层以 setTimeout(0) 上报的时机相同