camoufoxnative

package
v0.3.7 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: MIT Imports: 42 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

View Source
const (
	// AvailableRegionsURL 是官网在出口地区不受支持时跳转的页面
	AvailableRegionsURL = "https://aistudio.google.com/docs/available-regions"
	// AgeRequirementsURL 是官网在账户未满足年龄要求时跳转的页面
	AgeRequirementsURL = "https://aistudio.google.com/docs/troubleshoot-ai-studio#age-requirements"
	// WorkspaceURL 是官网在 Workspace 没有开放 AI Studio 时跳转的页面
	WorkspaceURL = "https://aistudio.google.com/docs/workspace"
	// AccountVerificationURL 是上游要求验证账户时给出的验证页面
	AccountVerificationURL = "https://aistudio.google.com/verify-account"
)

Variables

View Source
var ErrAccountVerification = errors.New("Google 要求先验证该账户才能继续使用 Gemini API,在官网完成账户验证")

ErrAccountVerification 表示 Google 要求先验证账户才能继续使用 Gemini API

View Source
var ErrAgeRequirement = errors.New("账户未满足 AI Studio 的年龄要求(年满 18 岁),在 Google 账户中核对生日或完成年龄验证")

ErrAgeRequirement 表示账户未满足 AI Studio 的年龄要求

View Source
var ErrAuthenticationRequired = errors.New("隔离登录态失效")

ErrAuthenticationRequired 表示隔离账户需要恢复登录

View Source
var ErrNoDisplay = errors.New("当前环境没有图形界面,无法打开 Camoufox 登录窗口:启动服务后在管理页面“添加账户”中选择“浏览器登录”,登录窗口显示在管理页面中")

ErrNoDisplay 表示本机没有图形界面,无法打开可见的登录窗口

View Source
var ErrProxyUnreachable = errors.New("代理不可达")

ErrProxyUnreachable 表示 Worker 载入 AI Studio 期间无法连接代理

View Source
var ErrRegionNotSupported = errors.New("AI Studio 不支持当前出口地区,为该账户或全局代理换用支持地区的出口")

ErrRegionNotSupported 表示 AI Studio 不支持当前出口地区

View Source
var ErrServiceRestricted = errors.New("Google 已限制该账户使用 AI Studio")

ErrServiceRestricted 表示 Google 限制该账户使用 AI Studio

View Source
var ErrWorkspaceDisabled = errors.New("账户所属的 Google Workspace 没有开放 AI Studio,联系组织管理员开启")

ErrWorkspaceDisabled 表示账户所属的 Google Workspace 没有开放 AI Studio

Functions

func AccountFingerprint added in v0.2.0

func AccountFingerprint(options Options) (map[string]any, error)

AccountFingerprint 返回账户固定 Camoufox 指纹配置,不存在时按当前版本生成并保存

func FindExecutable

func FindExecutable(ctx context.Context, proxy string) (string, error)

FindExecutable 定位与 camoufoxRelease 同版本的 Camoufox,都没有时经 proxy 下载,proxy 为空时直连

func FrontendBundle added in v0.3.7

func FrontendBundle(address *url.URL) bool

FrontendBundle 表示地址是官网前端主程序,即页面以 base-js 载入的 boq-makersuite 脚本 m=_b 模块

func GeneratePrompt added in v0.3.0

func GeneratePrompt(body []byte) (string, bool)

GeneratePrompt 返回 GenerateContent 正文最后一个轮次的文本,即官网用户在输入框中输入的提示词;最后一个轮次不是带文本的 user 轮次时返回 false

func HasDisplay added in v0.2.14

func HasDisplay() bool

HasDisplay 判断本机能否显示可见的浏览器窗口,Linux 上需要 DISPLAY 或 WAYLAND_DISPLAY

func Installed added in v0.2.17

func Installed() bool

Installed 表示本机已有与 camoufoxRelease 同版本的 Camoufox,不触发下载

func PersistAccountFingerprint

func PersistAccountFingerprint(sourceDirectory string, targetDirectory string) error

PersistAccountFingerprint 将隔离登录指纹保存到账户目录

func Prepare added in v0.3.7

func Prepare(ctx context.Context, proxy string) (string, error)

Prepare 返回同版本 Camoufox 的路径,未就绪时开始或加入进程内共用的后台准备并等到这一轮结束;ctx 结束只停止等待,不中止准备

func PrepareInBackground added in v0.3.7

func PrepareInBackground(proxy string)

PrepareInBackground 在 Camoufox 未就绪且没有进行中的准备时开始一轮后台准备,本机没有同版本 Camoufox 时经 proxy 下载

func ReadyPath added in v0.3.7

func ReadyPath() (string, error)

ReadyPath 返回已就绪的 Camoufox 路径,正在准备时返回 *PreparingError,最近一轮准备失败时返回失败原因

func RemoveStaleProfiles added in v0.1.7

func RemoveStaleProfiles() (int, error)

RemoveStaleProfiles 结束仍在使用创建进程已退出的临时 profile 的进程树,再删除这些 profile 并返回删除数量

Types

type AccessDenial added in v0.3.7

type AccessDenial struct {
	Err error
	URL string
}

AccessDenial 是官网拒绝出口或账户使用 AI Studio 的原因与跳转页

func DenialForMessage added in v0.3.7

func DenialForMessage(message string) *AccessDenial

DenialForMessage 返回官网对 GetLoggingContext 403 消息跳转的原因与页面,以及生成请求 403 消息要求验证账户时的验证页面,其他消息返回 nil

func PageDenial added in v0.3.7

func PageDenial(location *url.URL) *AccessDenial

PageDenial 返回 AI Studio 页面载入跳转到的地址对应的拒绝原因,其他地址返回 nil

func (*AccessDenial) Error added in v0.3.7

func (denial *AccessDenial) Error() string

func (*AccessDenial) Unwrap added in v0.3.7

func (denial *AccessDenial) Unwrap() error

type Download added in v0.2.17

type Download struct {
	Received int64 `json:"received"`
	Total    int64 `json:"total"`
}

Download 是正在进行的 Camoufox 下载的已收与总字节,总字节未知时为 0

func DownloadProgress added in v0.2.17

func DownloadProgress() (Download, bool)

DownloadProgress 返回正在进行的 Camoufox 下载,没有下载时 ok 为 false

type GenerateTurn added in v0.3.0

type GenerateTurn struct {
	Body       []byte
	ProofStart int
	ProofEnd   int
	Digest     string
}

GenerateTurn 是在页面界面运行的一轮 GenerateContent:Body 第 ProofStart 到 ProofEnd 字节是 proof 字段,发送时换成页面应用为 Digest 取得的 proof;Digest 为 binding 的 SHA-256 十六进制

type LiveView added in v0.2.14

type LiveView struct {
	// contains filtered or unexported fields
}

LiveView 把无头隔离登录浏览器的画面推给管理页登录窗口,并把窗口中的输入转发给浏览器

func NewLiveView added in v0.2.14

func NewLiveView() *LiveView

NewLiveView 创建尚未连接登录浏览器与登录窗口的 LiveView

func (*LiveView) Serve added in v0.2.14

func (view *LiveView) Serve(ctx context.Context, connection *websocket.Conn) error

Serve 把登录阶段、画面与页面对话框推给登录窗口连接并接收其输入,后连接的窗口替换先前的窗口;连接断开或 ctx 结束时关闭连接并返回

type LoginOptions

type LoginOptions struct {
	ExecutablePath string
	Directory      string
	Locale         string
	Timezone       string
	Proxy          string
	ProxyBypass    string
	Timeout        time.Duration
	Log            io.Writer
	View           *LiveView
}

LoginOptions 定义纯 Go 隔离登录环境,View 不为空时浏览器以无头方式运行,画面与输入经管理页登录窗口传递

type LoginResult

type LoginResult struct {
	StorageStateJSON []byte
	Email            string
	PageURL          string
	VerifiedAt       time.Time
	DriveError       string
	CloseError       string
}

LoginResult 返回隔离浏览器导出的 Playwright storage state

func Login

func Login(ctx context.Context, options LoginOptions) (result LoginResult, err error)

Login 启动隔离 Camoufox 供用户登录 Google,并在 AI Studio 可用后导出认证状态

type Options

type Options struct {
	ExecutablePath   string
	StorageStatePath string
	Model            string
	Locale           string
	Timezone         string
	Proxy            string
	ProxyBypass      string
	Headless         bool
	AuthUser         int
	CacheDirectory   string
	ReadyTimeout     time.Duration
	Log              io.Writer
	StartupProgress  func(StartupStage)
	// contains filtered or unexported fields
}

Options 定义单个 AI Studio 账户的原生 Camoufox runtime

type PageCatalog added in v0.3.0

type PageCatalog struct {
	Logging []byte
	Tier    []byte
	Models  []byte
	// Bundle 是页面载入的官网前端主程序地址
	Bundle string
}

PageCatalog 是会话页面载入时 GetLoggingContext、GetAiStudioBenefitTier 与 ListModels 的响应正文

type Preparation added in v0.3.7

type Preparation struct {
	Ready     bool      `json:"ready"`
	Preparing bool      `json:"preparing"`
	Download  *Download `json:"download,omitempty"`
	Error     string    `json:"error,omitempty"`
}

Preparation 是 Camoufox 的准备状态:是否就绪、是否正在下载或解压、正在进行的下载与最近一次准备失败的原因

func PreparationState added in v0.3.7

func PreparationState() Preparation

PreparationState 返回 Camoufox 的准备状态,没有准备过时按本机是否已有同版本 Camoufox 报告就绪

type PreparingError added in v0.3.7

type PreparingError struct {
	Download  *Download
	Remaining time.Duration
}

PreparingError 表示 Camoufox 正在准备,Download 为正在进行的下载,连接与解压期间为 nil;Remaining 为估计的剩余下载时间,无法估计时为 0

func (*PreparingError) Error added in v0.3.7

func (err *PreparingError) Error() string

type ProtectedResponse

type ProtectedResponse struct {
	StatusCode int
	Header     http.Header
	Body       io.ReadCloser
	Proof      string
}

ProtectedResponse 表示由固定指纹浏览器流式返回的 MakerSuite 响应,Proof 为界面运行时页面应用写入请求的 proof

type StartupStage

type StartupStage string

StartupStage 表示 Camoufox runtime 的启动阶段

const (
	// StartupPreparingBrowser 表示正在准备浏览器配置
	StartupPreparingBrowser StartupStage = "preparing_browser"
	// StartupLaunchingBrowser 表示正在启动浏览器进程
	StartupLaunchingBrowser StartupStage = "launching_browser"
	// StartupConnectingBiDi 表示正在连接 WebDriver BiDi
	StartupConnectingBiDi StartupStage = "connecting_bidi"
	// StartupLoadingAIStudio 表示正在载入 AI Studio 页面
	StartupLoadingAIStudio StartupStage = "loading_ai_studio"
	// StartupLocatingWAA 表示正在定位 WAA 服务
	StartupLocatingWAA StartupStage = "locating_waa"
	// StartupBootstrappingWAA 表示正在执行 WAA Bootstrap
	StartupBootstrappingWAA StartupStage = "bootstrapping_waa"
)

type State

type State struct {
	PID         int
	PageURL     string
	UserAgent   string
	SnapshotKey string
	Headers     http.Header
}

State 返回原生 runtime 的当前页面与 bootstrap 结果

type Worker

type Worker struct {
	// contains filtered or unexported fields
}

Worker 保存单个账户的长驻 Camoufox 与 WAA service

func Start

func Start(ctx context.Context, options Options) (*Worker, error)

Start 启动隔离 Camoufox 并完成一次官网 WAA bootstrap

func (*Worker) Close

func (worker *Worker) Close() error

Close 结束 BiDi session 并清理 Camoufox profile

func (*Worker) Generate added in v0.3.0

func (worker *Worker) Generate(ctx context.Context, turn GenerateTurn) (*ProtectedResponse, error)

Generate 像官网用户一样在标签页界面运行一轮 GenerateContent:按标签页上一轮的对话决定继续、Rerun 或先开新对话,输入框没有焦点时以可信指针点击输入框,写入最后一个 user 轮次文本的开头后点击 Run,页面应用自己取 proof、构造请求头并发出请求,发送时正文换成 turn 的正文;一轮成功完成后在后台新开对话,上游返回错误时下一轮在当前对话中继续;全部标签页都在运行对话时在新标签页中载入官网页面

func (*Worker) PageCatalog added in v0.3.0

func (worker *Worker) PageCatalog() PageCatalog

PageCatalog 返回当前页面载入时 GetLoggingContext、GetAiStudioBenefitTier 与 ListModels 的响应正文

func (*Worker) Proof

func (worker *Worker) Proof(ctx context.Context, digest string, prompt string) (string, error)

Proof 在一次页面调用中写入官网 prompt 并为 SHA-256 digest 生成 fresh WAA proof,页面值未同步时最多重试 5 秒

func (*Worker) ProtocolHeaders

func (worker *Worker) ProtocolHeaders(ctx context.Context) (http.Header, error)

ProtocolHeaders 返回官网为 GenerateContent 构造的六个公共头

func (*Worker) Reload added in v0.3.0

func (worker *Worker) Reload(ctx context.Context) error

Reload 像官网用户一样在当前标签页中按官网冷启动重新载入页面;当前标签页有进行中的请求时改在新标签页中载入并切换过去,原标签页在其中的请求结束后关闭

func (*Worker) SendProtected

func (worker *Worker) SendProtected(ctx context.Context, rawURL string, headers http.Header, body []byte) (*ProtectedResponse, error)

SendProtected 通过固定指纹 Camoufox 页面发送请求,保留原生 TLS、HTTP/2、请求头、Cookie 和页面指纹;请求头带 Priority: u=0 时在一次 Pause 按键的处理中发出

func (*Worker) SetCookies added in v0.3.3

func (worker *Worker) SetCookies(ctx context.Context, encoded []byte) error

SetCookies 按 storage state 的 Cookie 格式写入固定指纹浏览器

func (*Worker) State

func (worker *Worker) State() State

State 返回 runtime 的不可变状态副本

func (*Worker) StorageCookies

func (worker *Worker) StorageCookies(ctx context.Context) ([]byte, error)

StorageCookies 导出当前固定指纹浏览器 Cookie,启动时写入的 Cookie 保持写入顺序,之后出现的 Cookie 排在其后

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL