browser

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2026 License: MIT Imports: 15 Imported by: 1 module, 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 DefaultTarget = "127.0.0.1:9222"

DefaultTarget is Chrome's conventional remote-debugging address.

Variables

View Source
var ErrCDPUnavailable = errors.New("Chrome DevTools unavailable (start Chrome with --remote-debugging-port=9222)")

ErrCDPUnavailable means the Chrome DevTools endpoint could not be reached.

Functions

func ResolveTarget

func ResolveTarget(target string) (string, error)

ResolveTarget normalizes a CDP target string into an HTTP endpoint or a websocket debugger URL. Empty target defaults to 127.0.0.1:9222.

Accepted forms:

  • port: "9224"
  • host:port: "127.0.0.1:9224"
  • http(s) CDP endpoint: "http://127.0.0.1:9224"
  • websocket debugger URL: "ws://127.0.0.1:9224/devtools/browser/..."

Types

type Client

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

Client is a minimal Chrome DevTools Protocol client for Storage.setCookies.

func Connect

func Connect(ctx context.Context, target string) (*Client, error)

Connect dials a CDP target: an HTTP endpoint, whose browser websocket is looked up, or a websocket debugger URL.

func (*Client) Close

func (c *Client) Close() error

Close closes the websocket connection.

func (*Client) Endpoint

func (c *Client) Endpoint() string

Endpoint returns the resolved CDP HTTP endpoint or websocket URL used to connect.

func (*Client) SetCookies

func (c *Client) SetCookies(ctx context.Context, cookies []CookieParam) (int, error)

SetCookies injects cookies via Storage.setCookies, falling back to one-by-one when the batch call fails. Returns how many cookies were set successfully. Cookie values are never logged.

type CookieConversion

type CookieConversion struct {
	Cookies []CookieParam
	Skipped int
}

CookieConversion holds CookieParams ready for CDP and how many were skipped.

func CookiesToParams

func CookiesToParams(stored []auth.StoredCookie) CookieConversion

CookiesToParams converts stored session cookies into CDP CookieParams. Cookies with empty Name or Value are skipped. Cookie values are never logged.

type CookieParam

type CookieParam struct {
	Name     string   `json:"name"`
	Value    string   `json:"value"`
	URL      string   `json:"url,omitempty"`
	Domain   string   `json:"domain,omitempty"`
	Path     string   `json:"path,omitempty"`
	Secure   bool     `json:"secure,omitempty"`
	HTTPOnly bool     `json:"httpOnly,omitempty"`
	Expires  *float64 `json:"expires,omitempty"`
	SameSite string   `json:"sameSite,omitempty"`
}

CookieParam is the CDP Network.CookieParam subset used by Storage.setCookies. Value is included for CDP only and must never be logged or printed.

type SyncResult

type SyncResult struct {
	CDP       string `json:"cdp"`
	Attempted int    `json:"attempted"`
	Set       int    `json:"set"`
	Skipped   int    `json:"skipped"`
}

SyncResult is the JSON-safe outcome of syncing cookies into a browser.

func SyncCookies

func SyncCookies(ctx context.Context, sessionFile, target string) (*SyncResult, error)

SyncCookies loads the saved session and injects cookies into Chrome over CDP.

Jump to

Keyboard shortcuts

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