urltracker

package
v0.12.45 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxScanBytes      = 8 * 1024 // Only scan first 8KB of output (startup phase)
	MaxURLsPerProcess = 5        // Max URLs to store per process
)

Constants for URL detection

Variables

View Source
var DevServerURLRegex = regexp.MustCompile(`https?://(?:localhost|127\.0\.0\.1|0\.0\.0\.0|\[::1\]):\d+[^\s\)\]\}'"<>]*`)

DevServerURLRegex matches localhost-like dev server URLs. Only matches true localhost addresses (localhost, 127.0.0.1, 0.0.0.0, [::1]). Network IP addresses (192.168.x.x, 10.x.x.x) are excluded to avoid duplicate proxies.

Functions

func MatchesURLPattern

func MatchesURLPattern(line, pattern string) bool

MatchesURLPattern checks if a line matches a URL matcher pattern. Supports patterns like:

  • "Local:\s*{url}" - matches lines containing "Local:" followed by a URL
  • "(Local|Network):\s*{url}" - matches lines with "Local:" or "Network:"
  • "{url}" - matches any line with a URL

func NormalizeURL

func NormalizeURL(u string) string

NormalizeURL normalizes a URL for consistent comparison. Removes ANSI escape codes, trailing slashes and punctuation, lowercases the scheme and host.

func ParseDevServerURLs

func ParseDevServerURLs(output []byte) []string

ParseDevServerURLs extracts dev server URLs from output. Only returns localhost-like URLs that look like dev servers.

func ParseDevServerURLsWithMatchers

func ParseDevServerURLsWithMatchers(output []byte, matchers []string) []string

ParseDevServerURLsWithMatchers extracts URLs matching specific patterns. If matchers is nil or empty, returns all detected URLs. Matchers support patterns like "Local:\s*{url}" or "(Local|Network):\s*{url}".

func ShouldIgnoreURL

func ShouldIgnoreURL(u string) bool

ShouldIgnoreURL returns true if the URL should be ignored.

Types

type URLTracker

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

URLTracker monitors process output and extracts dev server URLs. Focused on capturing localhost URLs from dev server startup (e.g., pnpm dev). URLs are stored persistently per process ID so they survive buffer overflow.

func NewURLTracker

func NewURLTracker(pm *process.ProcessManager, config URLTrackerConfig) *URLTracker

NewURLTracker creates a new URL tracker.

func (*URLTracker) ClearProcess

func (t *URLTracker) ClearProcess(processID string)

ClearProcess removes URL tracking for a process.

func (*URLTracker) GetURLs

func (t *URLTracker) GetURLs(processID string) []string

GetURLs returns the detected URLs for a process.

func (*URLTracker) OnProcessFirstSeen

func (t *URLTracker) OnProcessFirstSeen(fn func(processID string))

OnProcessFirstSeen sets the callback invoked when a process is first scanned.

func (*URLTracker) OnProcessStopped

func (t *URLTracker) OnProcessStopped(fn func(processID string))

OnProcessStopped sets the callback invoked when a process is removed.

func (*URLTracker) OnURLDetected

func (t *URLTracker) OnURLDetected(fn func(processID, url string))

OnURLDetected sets the callback invoked when a new URL is detected.

func (*URLTracker) SetURLMatchers

func (t *URLTracker) SetURLMatchers(processID string, matchers []string)

SetURLMatchers sets URL matcher patterns for a specific process. Matchers support patterns like "Local:\\s*{url}" or "(Local|Network):\\s*{url}".

func (*URLTracker) Start

func (t *URLTracker) Start(ctx context.Context)

Start begins periodic URL scanning.

type URLTrackerConfig

type URLTrackerConfig struct {
	// ScanInterval is how often to scan process output for URLs.
	// Default: 500ms (fast for quick startup detection)
	ScanInterval time.Duration
}

URLTrackerConfig configures the URL tracker.

func DefaultURLTrackerConfig

func DefaultURLTrackerConfig() URLTrackerConfig

DefaultURLTrackerConfig returns sensible defaults.

Jump to

Keyboard shortcuts

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