cloakdriver

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 19 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

Overview

Package cloakdriver provides Go bindings for CloakBrowser-Manager REST API and CDP automation. The package is the v2.0 fallback transport for sites where cookie-only HTTP probing is blocked by Cloudflare/ja3 fingerprinting.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrManagerNotFound      = errors.New("cloakbrowser-manager: profile not found")
	ErrManagerAuthFailed    = errors.New("cloakbrowser-manager: auth failed (check token)")
	ErrManagerServerError   = errors.New("cloakbrowser-manager: 5xx server error")
	ErrManagerDNSFailed     = errors.New("cloakbrowser-manager: DNS resolution failed")
	ErrManagerConnRefused   = errors.New("cloakbrowser-manager: connection refused")
	ErrManagerTimeout       = errors.New("cloakbrowser-manager: timeout")
	ErrManagerProtocolError = errors.New("cloakbrowser-manager: protocol/parse error")
)

Sentinel errors classify Manager failures (R19).

Functions

This section is empty.

Types

type CDPSession

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

CDPSession wraps a chromedp browser context bound to a CloakBrowser profile's CDP WebSocket URL (returned by Manager's POST /api/profiles/{id}/launch). Sessions are stateful; callers must Close() to release allocator and task goroutines.

func NewCDPSession

func NewCDPSession(parent context.Context, cdpURL string, header http.Header) (*CDPSession, error)

NewCDPSession opens a chromedp remote allocator connection to cdpURL and verifies the connection with a no-op chromedp.Do within a 5s timeout. The returned session must be Close()d.

header 不为 nil 表示 cdpURL 是经 Manager 转发的地址(见 ProfileLaunchResult.CdpHeader):原样连接, 不去查 /json/version(那个请求带不上令牌),握手带上 header。

func (*CDPSession) Close

func (s *CDPSession) Close()

Close releases allocator and task contexts. Safe to call multiple times.

func (*CDPSession) GetCookies

func (s *CDPSession) GetCookies(ctx context.Context, urls ...string) ([]*network.Cookie, error)

GetCookies returns all cookies currently in the browser for the given URLs.

func (*CDPSession) InjectCookies

func (s *CDPSession) InjectCookies(ctx context.Context, targetURL string, cookies []*http.Cookie) error

InjectCookies enforces R35: clear all browser cookies first, then set the supplied cookies. This prevents stale-cookie pollution from prior sessions in the persistent CloakBrowser profile.

从站点配置的 Cookie 串解析出的 Cookie 没有 Domain 与 Path,这类 Cookie 按 targetURL 设置 (Chrome 由 url 推出域名),Path 取 "/";否则 Network.setCookie 会因缺少 url 与 domain 而失败。

func (*CDPSession) LoadPageAndExtract

func (s *CDPSession) LoadPageAndExtract(
	ctx context.Context,
	targetURL string,
	waitForSelector string,
	extract func(htmlOuter string) error,
) error

LoadPageAndExtract navigates to targetURL, waits for waitForSelector to become visible, and runs extract with the rendered page's outer HTML. Used by schema-specific drivers (T11-T14) to parse user/profile pages.

func (*CDPSession) TaskContext

func (s *CDPSession) TaskContext() context.Context

TaskContext returns the underlying chromedp task context for advanced callers (T11-T14 schema drivers may need direct chromedp.Do access).

type ManagerClient

type ManagerClient interface {
	LaunchProfile(ctx context.Context, profileID string) (*ProfileLaunchResult, error)
	GetProfileStatus(ctx context.Context, profileID string) (*ProfileStatus, error)
	StopProfile(ctx context.Context, profileID string) error
	DeleteProfile(ctx context.Context, profileID string) error
	ManagerStatus(ctx context.Context) error // GET /api/status — used by test-connection
	ManagerStatusFull(ctx context.Context) (*ManagerStatusInfo, error)
}

ManagerClient is the abstraction over CloakBrowser-Manager REST. Implementations: real HTTP client (manager_client.go), httptest mock (tests).

func NewManagerClient

func NewManagerClient(baseURL, token string, timeout time.Duration) ManagerClient

NewManagerClient builds a ManagerClient bound to the given Manager base URL. A zero timeout uses defaultManagerTimeout (10s).

type ManagerStatusInfo

type ManagerStatusInfo struct {
	Status  string `json:"status,omitempty"`
	Version string `json:"version,omitempty"`
}

ManagerStatusInfo is the Manager-level status payload returned by GET /api/status. Used by the test-connection endpoint to report Manager version on success.

type ProfileLaunchResult

type ProfileLaunchResult struct {
	ProfileID string    `json:"profile_id"`
	CdpURL    string    `json:"cdp_url"`
	VncURL    string    `json:"vnc_url,omitempty"`
	StartedAt time.Time `json:"started_at"`
	// CdpHeader 不为 nil 时,CdpURL 是经 Manager 转发的 websocket 地址:连接时原样使用(不去查 /json/version),
	// 握手带上这些请求头(Manager 的 Bearer 令牌)。新版 Manager(v0.1.x)的 cdp_url 是相对路径
	// /api/profiles/{id}/cdp,转发也要令牌,LaunchProfile 会把它补成完整地址并填上这里。
	CdpHeader http.Header `json:"-"`
}

ProfileLaunchResult is what Manager returns after POST /api/profiles/{id}/launch.

type ProfileStatus

type ProfileStatus struct {
	ProfileID string `json:"profile_id"`
	Running   bool   `json:"running"`
	CdpURL    string `json:"cdp_url,omitempty"`
}

ProfileStatus is what Manager returns from GET /api/profiles/{id}/status.

Directories

Path Synopsis
Package gazelle implements the Gazelle-schema CloakBrowser driver (T13).
Package gazelle implements the Gazelle-schema CloakBrowser driver (T13).
Package mtorrent implements the mTorrent (M-Team) CloakBrowser driver.
Package mtorrent implements the mTorrent (M-Team) CloakBrowser driver.
Package nexusphp implements the NexusPHP-schema CloakBrowser driver.
Package nexusphp implements the NexusPHP-schema CloakBrowser driver.
Package transport 把 CloakBrowser 的各架构驱动接成登录探测的后备通道(sitelogin.Transport)。
Package transport 把 CloakBrowser 的各架构驱动接成登录探测的后备通道(sitelogin.Transport)。
Package unit3d implements the Unit3D-schema CloakBrowser driver.
Package unit3d implements the Unit3D-schema CloakBrowser driver.

Jump to

Keyboard shortcuts

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