session

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunDaemon

func RunDaemon(opts Options) error

Types

type AuthProfile

type AuthProfile struct {
	Name             string `json:"name"`
	URL              string `json:"url"`
	Username         string `json:"username"`
	Password         string `json:"password,omitempty"`
	UsernameSelector string `json:"usernameSelector,omitempty"`
	PasswordSelector string `json:"passwordSelector,omitempty"`
	SubmitSelector   string `json:"submitSelector,omitempty"`
}

AuthProfile represents a saved authentication profile.

type AuthVault

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

AuthVault manages a local credential store.

func NewAuthVault

func NewAuthVault() (*AuthVault, error)

NewAuthVault creates or loads the auth vault from ~/.ko-browser/auth.json.

func (*AuthVault) Delete

func (v *AuthVault) Delete(name string) error

Delete removes a profile by name.

func (*AuthVault) Get

func (v *AuthVault) Get(name string) (AuthProfile, bool)

Get returns a profile by name.

func (*AuthVault) List

func (v *AuthVault) List() []AuthProfile

List returns all profile names sorted.

func (*AuthVault) Save

func (v *AuthVault) Save(p AuthProfile) error

Save stores a profile in the vault.

type Client

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

func NewClient

func NewClient(opts Options) *Client

func (*Client) Back

func (c *Client) Back() error

func (*Client) Check

func (c *Client) Check(id int) error

func (*Client) ClearGeo

func (c *Client) ClearGeo() error

func (*Client) Click

func (c *Client) Click(id int) error

func (*Client) ClickNewTab

func (c *Client) ClickNewTab(id int) error

func (*Client) ClipboardCopy

func (c *Client) ClipboardCopy() error

func (*Client) ClipboardPaste

func (c *Client) ClipboardPaste() error

func (*Client) ClipboardRead

func (c *Client) ClipboardRead() (string, error)

func (*Client) ClipboardWrite

func (c *Client) ClipboardWrite(text string) error

func (*Client) Close

func (c *Client) Close() error

func (*Client) Confirm

func (c *Client) Confirm(id string) error

func (*Client) ConsoleClear

func (c *Client) ConsoleClear() error

func (*Client) ConsoleMessages

func (c *Client) ConsoleMessages(level string) ([]browser.ConsoleMessage, error)

func (*Client) ConsoleStart

func (c *Client) ConsoleStart() error

func (*Client) CookieDelete

func (c *Client) CookieDelete(name string) error

func (*Client) CookieSet

func (c *Client) CookieSet(cookie browser.CookieInfo) error

func (*Client) CookiesClear

func (c *Client) CookiesClear() error

func (*Client) CookiesGet

func (c *Client) CookiesGet() ([]browser.CookieInfo, error)

func (*Client) DblClick

func (c *Client) DblClick(id int) error

func (*Client) Deny

func (c *Client) Deny(id string) error

func (*Client) DiffScreenshot

func (c *Client) DiffScreenshot(baselineFile, outputFile string, threshold float64, fullPage bool) (Response, error)

func (*Client) DiffSnapshot

func (c *Client) DiffSnapshot(baselineFile string, snapOpts browser.SnapshotOptions) (Response, error)

func (*Client) DiffURL

func (c *Client) DiffURL(url1, url2 string, includeScreenshot, fullPage bool, threshold float64, snapOpts browser.SnapshotOptions) (Response, error)

func (*Client) Download

func (c *Client) Download(id int, saveDir string) (string, error)

func (*Client) Drag

func (c *Client) Drag(srcID, dstID int) error

func (*Client) Eval

func (c *Client) Eval(expression string) (string, error)

func (*Client) ExportState

func (c *Client) ExportState(path string) error

func (*Client) Fill

func (c *Client) Fill(id int, text string) error

func (*Client) FindAlt

func (c *Client) FindAlt(text string, exact bool) (string, error)

func (*Client) FindLabel

func (c *Client) FindLabel(label string) (string, error)

func (*Client) FindLabelExact

func (c *Client) FindLabelExact(label string, exact bool) (string, error)

func (*Client) FindLast

func (c *Client) FindLast(cssSelector string) (string, error)

func (*Client) FindNth

func (c *Client) FindNth(cssSelector string, n int) (string, error)

func (*Client) FindPlaceholder

func (c *Client) FindPlaceholder(text string, exact bool) (string, error)

func (*Client) FindRole

func (c *Client) FindRole(role, name string) (string, error)

func (*Client) FindRoleExact

func (c *Client) FindRoleExact(role, name string, exact bool) (string, error)

func (*Client) FindTestID

func (c *Client) FindTestID(testID string) (string, error)

func (*Client) FindText

func (c *Client) FindText(text string) (string, error)

func (*Client) FindTextExact

func (c *Client) FindTextExact(text string, exact bool) (string, error)

func (*Client) FindTitle

func (c *Client) FindTitle(text string, exact bool) (string, error)

func (*Client) Focus

func (c *Client) Focus(id int) error

func (*Client) Forward

func (c *Client) Forward() error

func (*Client) GetAttr

func (c *Client) GetAttr(id int, name string) (string, error)

func (*Client) GetBox

func (c *Client) GetBox(id int) (*browser.BoxResult, error)

func (*Client) GetCDPURL

func (c *Client) GetCDPURL() (string, error)

func (*Client) GetCount

func (c *Client) GetCount(cssSelector string) (int, error)

func (*Client) GetHTML

func (c *Client) GetHTML(id int) (string, error)

func (*Client) GetStyles

func (c *Client) GetStyles(id int) (string, error)

func (*Client) GetText

func (c *Client) GetText(id int) (string, error)

func (*Client) GetTitle

func (c *Client) GetTitle() (string, error)

func (*Client) GetURL

func (c *Client) GetURL() (string, error)

func (*Client) GetValue

func (c *Client) GetValue(id int) (string, error)

func (*Client) Highlight

func (c *Client) Highlight(id int) error

func (*Client) Hover

func (c *Client) Hover(id int) error

func (*Client) ImportState

func (c *Client) ImportState(path string) error

func (*Client) IsChecked

func (c *Client) IsChecked(id int) (bool, error)

func (*Client) IsEnabled

func (c *Client) IsEnabled(id int) (bool, error)

func (*Client) IsVisible

func (c *Client) IsVisible(id int) (bool, error)

func (*Client) KeyboardInsertText

func (c *Client) KeyboardInsertText(text string) error

func (*Client) KeyboardType

func (c *Client) KeyboardType(text string) error

func (*Client) MouseClick

func (c *Client) MouseClick(x, y float64, button string) error

func (*Client) MouseDown

func (c *Client) MouseDown(x, y float64, button string) error

func (*Client) MouseMove

func (c *Client) MouseMove(x, y float64) error

func (*Client) MouseUp

func (c *Client) MouseUp(x, y float64, button string) error

func (*Client) MouseWheel

func (c *Client) MouseWheel(x, y, deltaX, deltaY float64) error

func (*Client) NetworkClearRequests

func (c *Client) NetworkClearRequests() error

func (*Client) NetworkRequests

func (c *Client) NetworkRequests() ([]browser.NetworkRequest, error)

func (*Client) NetworkRoute

func (c *Client) NetworkRoute(pattern, action string) error

func (*Client) NetworkStartLogging

func (c *Client) NetworkStartLogging() error

func (*Client) NetworkUnroute

func (c *Client) NetworkUnroute(pattern string) error

func (*Client) Open

func (c *Client) Open(url string) error

func (*Client) OpenDevTools

func (c *Client) OpenDevTools() error

func (*Client) PDF

func (c *Client) PDF(path string, args PDFArgs) error

func (*Client) PageErrors

func (c *Client) PageErrors() ([]browser.PageError, error)

func (*Client) PageErrorsClear

func (c *Client) PageErrorsClear() error

func (*Client) Press

func (c *Client) Press(key string) error

func (*Client) ProfilerStart

func (c *Client) ProfilerStart() error

func (*Client) ProfilerStop

func (c *Client) ProfilerStop(outputFile string) error

func (*Client) RecordStart

func (c *Client) RecordStart(outputPath string) error

func (*Client) RecordStop

func (c *Client) RecordStop() (int, error)

func (*Client) Reload

func (c *Client) Reload() error

func (*Client) Screenshot

func (c *Client) Screenshot(path string, args ScreenshotArgs) error

func (*Client) ScreenshotAnnotated

func (c *Client) ScreenshotAnnotated(path string, args ScreenshotArgs) error

func (*Client) Scroll

func (c *Client) Scroll(direction string, amount int) error

func (*Client) ScrollIntoView

func (c *Client) ScrollIntoView(id int) error

func (*Client) Select

func (c *Client) Select(id int, values ...string) error

func (*Client) SessionInfo

func (c *Client) SessionInfo() (string, error)

func (*Client) SetColorScheme

func (c *Client) SetColorScheme(scheme string) error

func (*Client) SetCredentials

func (c *Client) SetCredentials(user, pass string) error

func (*Client) SetDevice

func (c *Client) SetDevice(name string) error

func (*Client) SetGeo

func (c *Client) SetGeo(lat, lon float64) error

func (*Client) SetHeaders

func (c *Client) SetHeaders(headers map[string]string) error

func (*Client) SetMedia

func (c *Client) SetMedia(features []browser.MediaFeature) error

func (*Client) SetOffline

func (c *Client) SetOffline(offline bool) error

func (*Client) SetViewport

func (c *Client) SetViewport(width, height int) error

func (*Client) SetViewportWithScale

func (c *Client) SetViewportWithScale(width, height int, scale float64) error

func (*Client) Snapshot

func (c *Client) Snapshot(opts browser.SnapshotOptions) (Response, error)

func (*Client) StorageClear

func (c *Client) StorageClear(storageType string) error

func (*Client) StorageDelete

func (c *Client) StorageDelete(storageType, key string) error

func (*Client) StorageGet

func (c *Client) StorageGet(storageType, key string) (string, error)

func (*Client) StorageGetAll

func (c *Client) StorageGetAll(storageType string) (map[string]string, error)

func (*Client) StorageSet

func (c *Client) StorageSet(storageType, key, value string) error

func (*Client) TabClose

func (c *Client) TabClose(index int) error

func (*Client) TabList

func (c *Client) TabList() ([]browser.TabInfo, error)

func (*Client) TabNew

func (c *Client) TabNew(url string) error

func (*Client) TabSwitch

func (c *Client) TabSwitch(index int) error

func (*Client) TraceStart

func (c *Client) TraceStart(categories string) error

func (*Client) TraceStop

func (c *Client) TraceStop(outputFile string) error

func (*Client) Type

func (c *Client) Type(id int, text string) error

func (*Client) Uncheck

func (c *Client) Uncheck(id int) error

func (*Client) Upload

func (c *Client) Upload(id int, files ...string) error

func (*Client) Wait

func (c *Client) Wait(d time.Duration) error

func (*Client) WaitDownload

func (c *Client) WaitDownload(saveDir string) (string, error)

func (*Client) WaitFunc

func (c *Client) WaitFunc(expression string) error

func (*Client) WaitHidden

func (c *Client) WaitHidden(cssSelector string) error

func (*Client) WaitLoad

func (c *Client) WaitLoad() error

func (*Client) WaitSelector

func (c *Client) WaitSelector(cssSelector string) error

func (*Client) WaitText

func (c *Client) WaitText(text string) error

func (*Client) WaitURL

func (c *Client) WaitURL(pattern string) error

type ConfirmStore

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

ConfirmStore manages pending actions that require confirmation.

func NewConfirmStore

func NewConfirmStore(categories []string, timeout time.Duration) *ConfirmStore

NewConfirmStore creates a new confirmation store. categories is a set of action names that require confirmation.

func (*ConfirmStore) Add

func (cs *ConfirmStore) Add(command, argsDesc string) *PendingAction

Add registers a pending action and returns its ID.

func (*ConfirmStore) Confirm

func (cs *ConfirmStore) Confirm(id string) error

Confirm approves a pending action.

func (*ConfirmStore) Deny

func (cs *ConfirmStore) Deny(id string) error

Deny rejects a pending action.

func (*ConfirmStore) NeedsConfirmation

func (cs *ConfirmStore) NeedsConfirmation(command string) bool

NeedsConfirmation checks if a command category requires confirmation.

type Options

type Options struct {
	Name      string
	Headed    bool
	Timeout   time.Duration
	Debug     bool
	Profile   string
	StatePath string

	// Phase 8.3: Global options
	UserAgent         string
	Proxy             string
	ProxyBypass       string
	IgnoreHTTPSErrors bool
	AllowFileAccess   bool
	Extensions        []string
	ExtraArgs         []string
	DownloadPath      string
	ScreenshotDir     string
	ScreenshotFormat  string

	// Phase 8.4: Confirmation
	ConfirmActions []string
}

type PDFArgs

type PDFArgs struct {
	Landscape bool `json:"landscape,omitempty"`
	PrintBG   bool `json:"printBG,omitempty"`
}

PDFArgs holds arguments for the pdf command.

type PendingAction

type PendingAction struct {
	ID        string    `json:"id"`
	Command   string    `json:"command"`
	Args      string    `json:"args"`
	CreatedAt time.Time `json:"createdAt"`
	// contains filtered or unexported fields
}

PendingAction represents an action awaiting confirmation.

func (*PendingAction) Wait

func (pa *PendingAction) Wait() bool

Wait blocks until the pending action is confirmed or denied. Returns true if confirmed, false if denied or timed out.

type Request

type Request struct {
	Command         string                  `json:"command"`
	URL             string                  `json:"url,omitempty"`
	ID              int                     `json:"id,omitempty"`
	Text            string                  `json:"text,omitempty"`
	Key             string                  `json:"key,omitempty"`
	Values          []string                `json:"values,omitempty"`
	Direction       string                  `json:"direction,omitempty"`
	Amount          int                     `json:"amount,omitempty"`
	AttrName        string                  `json:"attrName,omitempty"`
	CSSSelector     string                  `json:"cssSelector,omitempty"`
	Expression      string                  `json:"expression,omitempty"`
	WaitDuration    time.Duration           `json:"waitDuration,omitempty"`
	SnapshotOptions browser.SnapshotOptions `json:"snapshotOptions,omitempty"`

	// Phase 3: Screenshot/PDF/Eval/Find
	FilePath       string         `json:"filePath,omitempty"`
	ScreenshotArgs ScreenshotArgs `json:"screenshotArgs,omitempty"`
	PDFArgs        PDFArgs        `json:"pdfArgs,omitempty"`
	Role           string         `json:"role,omitempty"`
	N              int            `json:"n,omitempty"`

	// Phase 4: Drag/Upload/Download/Mouse
	DstID    int      `json:"dstId,omitempty"`
	Files    []string `json:"files,omitempty"`
	SaveDir  string   `json:"saveDir,omitempty"`
	X        float64  `json:"x,omitempty"`
	Y        float64  `json:"y,omitempty"`
	DeltaX   float64  `json:"deltaX,omitempty"`
	DeltaY   float64  `json:"deltaY,omitempty"`
	MouseBtn string   `json:"mouseBtn,omitempty"`

	// Phase 5: Tab/Network/Storage
	TabIndex    int                `json:"tabIndex,omitempty"`
	Pattern     string             `json:"pattern,omitempty"`
	RouteAction string             `json:"routeAction,omitempty"`
	Cookie      browser.CookieInfo `json:"cookie,omitempty"`
	StorageType string             `json:"storageType,omitempty"`
	StorageKey  string             `json:"storageKey,omitempty"`
	StorageVal  string             `json:"storageVal,omitempty"`

	// Phase 6: Settings/Debug/Clipboard
	Width         int                    `json:"width,omitempty"`
	Height        int                    `json:"height,omitempty"`
	DeviceName    string                 `json:"deviceName,omitempty"`
	Lat           float64                `json:"lat,omitempty"`
	Lon           float64                `json:"lon,omitempty"`
	Offline       *bool                  `json:"offline,omitempty"`
	Headers       map[string]string      `json:"headers,omitempty"`
	User          string                 `json:"user,omitempty"`
	Pass          string                 `json:"pass,omitempty"`
	MediaFeatures []browser.MediaFeature `json:"mediaFeatures,omitempty"`
	ColorScheme   string                 `json:"colorScheme,omitempty"`
	ClipboardText string                 `json:"clipboardText,omitempty"`
	ConsoleLevel  string                 `json:"consoleLevel,omitempty"`

	// Phase 7: Advanced features
	Target            string  `json:"target,omitempty"`            // connect target (port or ws URL)
	BaselineFile      string  `json:"baselineFile,omitempty"`      // diff baseline file path
	OutputFile        string  `json:"outputFile,omitempty"`        // output file path for diff/trace/profiler/record
	Threshold         float64 `json:"threshold,omitempty"`         // screenshot diff threshold
	URL2              string  `json:"url2,omitempty"`              // second URL for diff url
	IncludeScreenshot bool    `json:"includeScreenshot,omitempty"` // diff url: also compare screenshots
	Categories        string  `json:"categories,omitempty"`        // trace categories
	StatePath         string  `json:"statePath,omitempty"`         // state import/export path

	// Phase 8: Missing commands/flags
	NewTab    bool    `json:"newTab,omitempty"`    // click with new tab
	Exact     bool    `json:"exact,omitempty"`     // exact matching for find
	Scale     float64 `json:"scale,omitempty"`     // viewport scale factor
	Cursor    bool    `json:"cursor,omitempty"`    // show cursor in snapshot
	ConfirmID string  `json:"confirmId,omitempty"` // confirmation ID for confirm/deny
}

type Response

type Response struct {
	OK           bool               `json:"ok"`
	Error        string             `json:"error,omitempty"`
	Text         string             `json:"text,omitempty"`
	RawCount     int                `json:"rawCount,omitempty"`
	ElementCount int                `json:"elementCount,omitempty"`
	IntResult    int                `json:"intResult,omitempty"`
	BoolResult   *bool              `json:"boolResult,omitempty"`
	Box          *browser.BoxResult `json:"box,omitempty"`
	FilePath     string             `json:"filePath,omitempty"`

	// Phase 5
	Tabs         []browser.TabInfo        `json:"tabs,omitempty"`
	Cookies      []browser.CookieInfo     `json:"cookies,omitempty"`
	Requests     []browser.NetworkRequest `json:"requests,omitempty"`
	StorageItems map[string]string        `json:"storageItems,omitempty"`

	// Phase 6
	ConsoleMessages []browser.ConsoleMessage `json:"consoleMessages,omitempty"`
	PageErrors      []browser.PageError      `json:"pageErrors,omitempty"`

	// Phase 7
	DiffResult     *browser.DiffSnapshotResult   `json:"diffResult,omitempty"`
	ScreenshotDiff *browser.DiffScreenshotResult `json:"screenshotDiff,omitempty"`
	DiffURLResult  *browser.DiffURLResult        `json:"diffURLResult,omitempty"`

	// Phase 8.4: Confirmation
	ConfirmationRequired bool   `json:"confirmationRequired,omitempty"`
	ConfirmID            string `json:"confirmId,omitempty"`
}

type ScreenshotArgs

type ScreenshotArgs struct {
	FullPage  bool `json:"fullPage,omitempty"`
	Quality   int  `json:"quality,omitempty"`
	ElementID int  `json:"elementID,omitempty"`
	Annotate  bool `json:"annotate,omitempty"`
}

ScreenshotArgs holds arguments for the screenshot command.

type SessionEntry

type SessionEntry struct {
	Name   string `json:"name"`
	Socket string `json:"socket"`
}

SessionEntry represents an active session found on the system.

func ListSessions

func ListSessions() ([]SessionEntry, error)

ListSessions scans the temp directory for active ko-browser session sockets.

Jump to

Keyboard shortcuts

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