engine

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Apr 1, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Package engine provides execution engines for running site scripts. It supports a fallback chain: QuickJS (fast, no browser) → CDP Browser (full browser).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RunScript

func RunScript(ctx context.Context, engines []Engine, s *script.Script, args map[string]string) (any, error)

RunScript tries each engine in order, returning the first successful result. If a result contains an "error" field (e.g. {"error":"HTTP 400"}), it is treated as a failure and the next engine is tried. If all engines fail, returns the last error.

Types

type Browser

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

Browser executes scripts in a real Chrome browser via CDP.

func NewBrowser

func NewBrowser(tp *transport.Transport, pauseFn transport.PauseFunc) *Browser

NewBrowser creates a new Browser engine backed by the given transport.

func (*Browser) Close

func (b *Browser) Close() error

func (*Browser) Name

func (b *Browser) Name() string

func (*Browser) Run

func (b *Browser) Run(ctx context.Context, s *script.Script, args map[string]string) (any, error)

type Engine

type Engine interface {
	// Run executes a script with the given arguments.
	Run(ctx context.Context, s *script.Script, args map[string]string) (any, error)

	// Name returns the engine name for logging.
	Name() string

	// Close releases resources held by the engine.
	Close() error
}

Engine can execute a site script with arguments and return a JSON-compatible result.

type QuickJS

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

QuickJS executes scripts in an embedded QuickJS runtime with a Go-backed fetch().

func NewQuickJS

func NewQuickJS(tp *transport.Transport) *QuickJS

NewQuickJS creates a new QuickJS engine backed by the given transport.

func (*QuickJS) Close

func (q *QuickJS) Close() error

func (*QuickJS) Name

func (q *QuickJS) Name() string

func (*QuickJS) Run

func (q *QuickJS) Run(_ context.Context, s *script.Script, args map[string]string) (result any, err error)

Jump to

Keyboard shortcuts

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