File size: 2,325 Bytes
6a7089a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | // Package engine provides a routing layer that decides whether to fulfil
// a request using the lightweight Gost-DOM engine ("lite") or Chrome (via CDP).
//
// The Router is the single entry point for handler code. Route rules are
// pluggable: callers add / remove rules without touching handlers, bridge,
// or any other package.
package engine
import "context"
// Capability identifies an operation the engine may handle.
type Capability string
const (
CapNavigate Capability = "navigate"
CapSnapshot Capability = "snapshot"
CapText Capability = "text"
CapClick Capability = "click"
CapType Capability = "type"
CapScreenshot Capability = "screenshot"
CapPDF Capability = "pdf"
CapEvaluate Capability = "evaluate"
CapCookies Capability = "cookies"
)
// Mode controls the engine selection strategy.
type Mode string
const (
ModeChrome Mode = "chrome" // always Chrome (default)
ModeLite Mode = "lite" // always lite (screenshot/pdf return 501)
ModeAuto Mode = "auto" // per-request routing via rules
)
// Decision is the routing verdict returned by a RouteRule.
type Decision int
const (
Undecided Decision = iota // rule has no opinion
UseLite // route to Gost-DOM
UseChrome // route to Chrome
)
// NavigateResult is the response from a navigation.
type NavigateResult struct {
TabID string `json:"tabId"`
URL string `json:"url"`
Title string `json:"title"`
}
// SnapshotNode represents a single node in the accessibility-style snapshot.
type SnapshotNode struct {
Ref string `json:"ref"`
Role string `json:"role"`
Name string `json:"name"`
Tag string `json:"tag,omitempty"`
Value string `json:"value,omitempty"`
Depth int `json:"depth"`
Interactive bool `json:"interactive,omitempty"`
}
// Engine is the minimal interface both lite and chrome wrappers implement.
type Engine interface {
Name() string
Navigate(ctx context.Context, url string) (*NavigateResult, error)
Snapshot(ctx context.Context, tabID, filter string) ([]SnapshotNode, error)
Text(ctx context.Context, tabID string) (string, error)
Click(ctx context.Context, tabID, ref string) error
Type(ctx context.Context, tabID, ref, text string) error
Capabilities() []Capability
Close() error
}
|