browsersignin

package
v0.6.1000 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package browsersignin lets a person sign in to a web site in a browser window and hands back the cookies that browser would send to one address: how a calendar feed whose address answers only a signed-in browser (a Google Workspace calendar, which redirects to Google's sign-in page) is read.

The browser is a Chromium-family one installed on this computer (Chrome, Edge, Chromium or Brave), started in a fresh profile of its own that is removed afterwards, so nothing of the person's everyday browser is read or changed. It is driven over a pipe the process inherits (Chrome's --remote-debugging-pipe, or --remote-debugging-io-pipes on Windows), never a debugging port another program could reach, and its downloads are denied, so an address that answers with a file does not leave the file on disk. While the window is open the browser's cookies for the address are read every PollEvery; each new set is handed to the caller's Ready, which says whether the address now answers as wanted. The first set Ready accepts is returned and the browser is closed.

Index

Constants

View Source
const EnvBrowser = "AGENTRY_BROWSER"

EnvBrowser names a Chromium-family browser's program to use instead of the ones Find looks for.

Variables

View Source
var (
	PollEvery  = 2 * time.Second
	RetryEvery = 15 * time.Second
)

PollEvery is how often the browser's cookies are read; RetryEvery is how often a set of cookies Ready did not accept is tried again while it stays the same, so a fetch that failed for a moment does not hold the sign-in until it ends.

View Source
var ErrClosed = errors.New("the browser window was closed before the sign-in was done")

ErrClosed says the person closed the browser window before the sign-in was done.

View Source
var ErrNoBrowser = errors.New("no Chrome, Edge, Chromium or Brave was found on this computer: install one, or set " + EnvBrowser + " to its program")

ErrNoBrowser says no Chromium-family browser was found.

Functions

func Find

func Find() (string, error)

Find is the program of a Chromium-family browser on this computer: the one EnvBrowser names, else the first of Chrome, Edge, Chromium and Brave found where each installs itself.

func Header(cookies []Cookie) string

Header is the Cookie header that sends cookies.

Types

type Cookie struct {
	Name   string `json:"name"`
	Value  string `json:"value"`
	Domain string `json:"domain"`
	Path   string `json:"path"`
	Secure bool   `json:"secure"`
	// PartitionKey is set on a cookie kept for one top-level site alone
	// (CHIPS); such a cookie is never sent to a plain fetch of the address.
	PartitionKey any `json:"partitionKey,omitempty"`
}

Cookie is one cookie as the browser keeps it.

func Match

func Match(cookies []Cookie, u *url.URL) []Cookie

Match are the cookies a browser would send with a request for u: those whose domain and path match it, a secure one only over https, none partitioned and none a Cookie header could not carry, longer paths first.

func Run

func Run(ctx context.Context, o Options) ([]Cookie, error)

Run opens the browser at o.URL and waits, until ctx ends, for a set of cookies o.Ready accepts, which it returns: those the browser sends to o.URL (Match).

type Options

type Options struct {
	// URL is the https address the window opens, and the one whose cookies
	// are read.
	URL string
	// Ready says whether the address answers as wanted when fetched with
	// the Cookie header given. An error stops the sign-in; false keeps the
	// window open.
	Ready func(ctx context.Context, header string) (bool, error)
	// Browser is the browser's program; empty finds one (Find).
	Browser string
	// Progress, when set, is told what the sign-in is waiting for.
	Progress func(string)
}

Options are what Run opens and how it knows the sign-in is done.

Jump to

Keyboard shortcuts

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