Documentation
¶
Index ¶
- func CreateMapLocalScript(dir, pattern, localPath string) (string, error)
- func CreateNewScript(dir string) (string, error)
- func DeleteScript(path string) error
- func EnsureScriptDir(dir string) error
- func GlobMatch(pattern, url string) bool
- func GlobMatchAny(patterns []string, url string) bool
- func LoadDir(dir string) (scripts []ScriptFile, errs []ScriptFile)
- func NewScriptTemplate() string
- func ToggleEnabled(path string) error
- type Engine
- func (e *Engine) Errors() []string
- func (e *Engine) LoadFromDir(dir string)
- func (e *Engine) LoadScript(name, source, urlPattern string) error
- func (e *Engine) Reload(dir string)
- func (e *Engine) RunOnRequest(ctx *RequestContext)
- func (e *Engine) RunOnResponse(ctx *ResponseContext, hostPath string)
- func (e *Engine) ScriptInfos() []ScriptInfo
- func (e *Engine) SetBreakpointController(ctrl breakpoint.Controller)
- type Manager
- func (m *Manager) CreateNew() (string, error)
- func (m *Manager) Delete(filePath string) error
- func (m *Manager) QuickAddMapLocal(pattern, localPath string) (string, error)
- func (m *Manager) Reload()
- func (m *Manager) ScriptByID(id string) (ScriptInfo, bool)
- func (m *Manager) ScriptDir() string
- func (m *Manager) Scripts() []ScriptInfo
- func (m *Manager) Toggle(filePath string) error
- type RequestContext
- type ResponseContext
- type ScriptCategory
- type ScriptFile
- type ScriptInfo
- type ScriptMeta
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CreateMapLocalScript ¶ added in v0.1.6
CreateMapLocalScript creates a map-local script in dir with the given URL pattern and local file path. Returns the path to the created file.
func CreateNewScript ¶
CreateNewScript creates dir if needed and writes the default template to a new file with the pattern script-*.js.
func EnsureScriptDir ¶
EnsureScriptDir creates the directory (and parents) if it doesn't exist.
func GlobMatch ¶
GlobMatch checks if a URL matches a glob pattern. Pattern format: scheme://host/path where * is a wildcard. Matching is case-insensitive. In the host part, * matches a single domain label (via path.Match). In the path part, * matches any substring including slashes.
func GlobMatchAny ¶
GlobMatchAny returns true if the URL matches any of the patterns.
func LoadDir ¶
func LoadDir(dir string) (scripts []ScriptFile, errs []ScriptFile)
LoadDir reads all .js files from dir and parses their headers. Missing dir returns empty results (not error). Bad files go into errs with Error set and Meta.Name as filename fallback.
func NewScriptTemplate ¶
func NewScriptTemplate() string
NewScriptTemplate returns the default script template with a fresh ID.
func ToggleEnabled ¶
ToggleEnabled reads a script file, flips its enabled state, and rewrites the file. If no "// enabled:" line exists, one is inserted before the closing "// ---" delimiter.
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine manages loaded JS scripts and runs them via goja.
func (*Engine) LoadFromDir ¶
LoadFromDir loads all scripts from dir via LoadDir. Enabled scripts are added to the engine; disabled scripts are tracked for ScriptInfos.
func (*Engine) LoadScript ¶
LoadScript adds a script with an optional URL pattern filter.
func (*Engine) Reload ¶
Reload clears dir-loaded scripts and re-loads from dir. Manually loaded scripts (via LoadScript) are kept intact.
func (*Engine) RunOnRequest ¶
func (e *Engine) RunOnRequest(ctx *RequestContext)
RunOnRequest executes all scripts' onRequest against the context.
func (*Engine) RunOnResponse ¶
func (e *Engine) RunOnResponse(ctx *ResponseContext, hostPath string)
RunOnResponse executes all scripts' onResponse against the context.
func (*Engine) ScriptInfos ¶
func (e *Engine) ScriptInfos() []ScriptInfo
ScriptInfos returns info about all dir-loaded scripts (including errors).
func (*Engine) SetBreakpointController ¶ added in v0.1.6
func (e *Engine) SetBreakpointController(ctrl breakpoint.Controller)
SetBreakpointController injects the breakpoint controller.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager wraps Engine and provides TUI-friendly script management.
func NewManager ¶
NewManager creates a Manager for the given engine and scripts directory.
func (*Manager) CreateNew ¶
CreateNew creates a new script from the default template and returns its path.
func (*Manager) QuickAddMapLocal ¶ added in v0.1.6
QuickAddMapLocal creates a map-local script with respondWith({file}).
func (*Manager) Reload ¶
func (m *Manager) Reload()
Reload re-scans the scripts directory and reloads the engine.
func (*Manager) ScriptByID ¶ added in v0.1.9
func (m *Manager) ScriptByID(id string) (ScriptInfo, bool)
ScriptByID finds a script by its unique ID.
func (*Manager) Scripts ¶
func (m *Manager) Scripts() []ScriptInfo
Scripts returns info about all scripts (enabled, disabled, and errored). Unlike Engine.ScriptInfos(), this scans the directory directly to include disabled and errored scripts that the engine doesn't load.
type RequestContext ¶
type RequestContext struct {
Method string
URL string
Headers http.Header
Body []byte
Blocked bool
Meta store.FlowMeta
Responded bool
ResponseStatus int
ResponseHeaders map[string]string
ResponseBody []byte
}
RequestContext is passed to JS onRequest handlers.
type ResponseContext ¶
type ResponseContext struct {
Status int
Headers http.Header
Body []byte
Meta store.FlowMeta
Responded bool
ResponseStatus int
ResponseHeaders map[string]string
ResponseBody []byte
}
ResponseContext is passed to JS onResponse handlers.
type ScriptCategory ¶ added in v0.1.6
type ScriptCategory string
ScriptCategory classifies scripts by detected API usage.
const ( CategoryScript ScriptCategory = "Script" CategoryMapLocal ScriptCategory = "Map Local" CategoryBreakpoint ScriptCategory = "Breakpoint" )
func DetectCategories ¶ added in v0.1.6
func DetectCategories(source string) []ScriptCategory
DetectCategories returns categories based on static source analysis.
type ScriptFile ¶
type ScriptFile struct {
Meta *ScriptMeta
Source string // JS body (after header)
FilePath string
Error string // non-empty if script failed to load
}
ScriptFile represents a loaded script file with metadata.
type ScriptInfo ¶
type ScriptInfo struct {
ID string
Name string
Matches []string
Enabled bool
FilePath string
Error string
Categories []ScriptCategory
}
ScriptInfo describes a loaded script for TUI display.
type ScriptMeta ¶
type ScriptMeta struct {
ID string `yaml:"id,omitempty"`
Name string `yaml:"name"`
Match []string `yaml:"match"`
Enabled *bool `yaml:"enabled,omitempty"`
}
ScriptMeta holds parsed YAML frontmatter from a script file.
func ParseHeader ¶
func ParseHeader(source string) (*ScriptMeta, string, error)
ParseHeader extracts YAML frontmatter from a script source string. The frontmatter is delimited by "// ---" lines, with each YAML line prefixed by "// ". Returns the parsed metadata, the remaining script body, and any error.
func (*ScriptMeta) IsEnabled ¶
func (m *ScriptMeta) IsEnabled() bool
IsEnabled returns the enabled state, defaulting to true when unset.