result

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jul 28, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package result defines chrome-cdp's uniform output envelope and the stable exit-code contract that both humans and the Claude skill depend on.

Index

Constants

View Source
const (
	ExitOK         = 0 // success
	ExitGeneric    = 1 // unclassified error
	ExitUsage      = 2 // bad flags/args, validated before touching Chrome
	ExitConnection = 3 // can't attach to / launch Chrome
	ExitTarget     = 4 // selector not found, nav/wait timeout, ambiguous/unknown target
	ExitCDP        = 5 // a CDP method returned an error
	ExitDaemon     = 6 // daemon not running / already running / stale lock
	ExitPermission = 7 // refused by policy (origin, verb, or upload root)
)

Exit codes are a stable, documented contract (see `chrome-cdp help exit-codes`). error.code strings are finer-grained and map onto these via ExitCodeFor.

View Source
const (
	CodeGeneric    = "generic"
	CodeUsage      = "usage"
	CodeConnection = "connection_failed"
	CodeNotDebug   = "not_debug_enabled"
	// CodeConsentPending is Chrome holding its browser-modal "Allow remote
	// debugging?" dialog: the port is open, the WebSocket upgrade is hanging,
	// and nothing is wrong except that a human has not answered yet. It shares
	// exit 3 with the other connection failures deliberately — a new number
	// would break the documented contract — but it is a distinct code because
	// the remedy is "click the dialog", not "check your setup".
	CodeConsentPending = "consent_pending"
	CodeTargetTimeout  = "target_timeout"
	CodeTargetNotFound = "target_not_found"
	CodeAmbiguous      = "ambiguous_target"
	CodeNoTarget       = "no_current_target"
	// CodeCoordinateOOB is a coordinate outside the current viewport (RFC-0014).
	// It is deliberately NOT clamped: a wrong-sized window is the usual cause,
	// and clamping would silently turn it into a mis-click somewhere real.
	// error.details carries the point and the viewport so a caller can
	// re-screenshot instead of guessing.
	CodeCoordinateOOB = "coordinate_out_of_bounds"
	CodeCDP           = "cdp_error"
	CodeDaemon        = "daemon_error"
	// CodePermissionDenied is the policy layer's refusal (RFC-0012, RFC-0006).
	// It is deliberately distinct from a target error: an agent must be able to
	// tell "policy forbids this, do not retry, tell the user" from "element not
	// found, retry differently".
	CodePermissionDenied = "permission_denied"
	// CodeAssertFailed is an assertion verdict, not a tool failure: the command
	// ran fine and the thing it was asked to check was true (console
	// --fail-on-match found messages). It maps to ExitGeneric so `nonzero means
	// the assertion tripped` keeps working in a CI `set -e` script, while the
	// code still lets a caller tell "the page logged an error" apart from "the
	// tool broke". Shared with RFC-0003's net --fail-on-match.
	CodeAssertFailed = "assertion_failed"
)

Stable error.code strings emitted in the envelope's error object. Named so call sites don't scatter bare string literals.

Variables

This section is empty.

Functions

func ExitCodeFor

func ExitCodeFor(code string) int

ExitCodeFor returns the process exit code for an error.code string, defaulting to ExitGeneric for anything unrecognized.

Types

type Envelope

type Envelope struct {
	OK        bool        `json:"ok"`
	Command   string      `json:"command"`
	Target    *TargetInfo `json:"target,omitempty"`
	Result    any         `json:"result,omitempty"`
	Error     *Err        `json:"error,omitempty"`
	ElapsedMs int64       `json:"elapsed_ms"`
}

Envelope is the single JSON shape every command emits under --json.

func (Envelope) ExitCode

func (e Envelope) ExitCode() int

ExitCode returns the process exit code implied by this envelope.

func (Envelope) JSON

func (e Envelope) JSON() ([]byte, error)

JSON renders the envelope as a single compact JSON value.

type Err

type Err struct {
	Code    string
	Message string
	Details map[string]any
}

Err is a structured command failure with optional context Details.

func (Err) MarshalJSON

func (e Err) MarshalJSON() ([]byte, error)

MarshalJSON flattens Details into the error object alongside code and message (e.g. {"code","message","selector",...}). encoding/json sorts map keys, so output is deterministic; code and message always win over any Details key.

type ExitCodeDoc

type ExitCodeDoc struct {
	Code int
	Desc string
}

ExitCodeDoc documents one exit code for `chrome-cdp exit-codes`.

func ExitCodes

func ExitCodes() []ExitCodeDoc

ExitCodes is the single source for the documented exit-code contract; the exit-codes command renders it rather than repeating the strings.

type TargetInfo

type TargetInfo struct {
	ID    string `json:"id"`
	Title string `json:"title"`
	URL   string `json:"url"`
}

TargetInfo identifies the tab a command acted on.

Jump to

Keyboard shortcuts

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