Documentation
¶
Index ¶
- Variables
- func Close(executionId string)
- func FailWithReason(page *rod.Page, e *proto.FetchRequestPaused) error
- func GetLfaAllowed(options *types.Options) bool
- func GetNetworkPolicy(ctx context.Context) *networkpolicy.NetworkPolicy
- func GlobalGuardBytesBufferAlloc() error
- func GlobalRestoreBytesBufferAlloc()
- func GuardThreadsOrDefault(current int) int
- func HasExecutionContext(ctx context.Context) bool
- func Init(options *types.Options) error
- func InitHeadless(options *types.Options)
- func IsHostAllowed(executionId string, targetUrl string) bool
- func IsLfaAllowed(options *types.Options) bool
- func IsLowOnMemory() bool
- func IsRestrictLocalNetworkAccess(options *types.Options) bool
- func NewJSRuntime() *goja.Runtime
- func NormalizePath(options *types.Options, filePath string) (string, error)
- func NormalizePathWithExecutionId(executionId string, filePath string) (string, error)
- func SetLfaAllowed(options *types.Options)
- func ShouldInit(id string) bool
- func StartActiveMemGuardian(ctx context.Context)
- func StopActiveMemGuardian()
- func ValidateNFailRequest(options *types.Options, page *rod.Page, e *proto.FetchRequestPaused) error
- func WithAutoExecutionContext(ctx context.Context) context.Context
- func WithExecutionID(ctx context.Context, executionContext *ExecutionContext) context.Context
- type ContextKey
- type Dialers
- type ExecutionContext
- type HTTPPool
- func (p *HTTPPool) Close()
- func (p *HTTPPool) GetClient(key string) (*retryablehttp.Client, bool)
- func (p *HTTPPool) GetOrCreateClient(clientKey, transportKey string, ...) (*retryablehttp.Client, error)
- func (p *HTTPPool) GetOrCreateTransport(key string, create func() (http.RoundTripper, error)) (http.RoundTripper, error)
Constants ¶
This section is empty.
Variables ¶
var ( ErrURLDenied = errkit.New("headless: url dropped by rule") ErrHostDenied = errorTemplate{/* contains filtered or unexported fields */} )
var ( MaxThreadsOnLowMemory = env.GetEnvOrDefault("MEMGUARDIAN_THREADS", 0) MaxBytesBufferAllocOnLowMemory = env.GetEnvOrDefault("MEMGUARDIAN_ALLOC", 0) )
var ( // LfaAllowed means local file access is allowed LfaAllowed *mapsutil.SyncLockMap[string, bool] )
var Memoizer *memoize.Memoizer
Functions ¶
func FailWithReason ¶
func FailWithReason(page *rod.Page, e *proto.FetchRequestPaused) error
FailWithReason fails request with AccessDenied reason
func GetLfaAllowed ¶ added in v3.4.8
func GetNetworkPolicy ¶ added in v3.4.8
func GetNetworkPolicy(ctx context.Context) *networkpolicy.NetworkPolicy
func GlobalGuardBytesBufferAlloc ¶ added in v3.2.1
func GlobalGuardBytesBufferAlloc() error
Global setting
func GlobalRestoreBytesBufferAlloc ¶ added in v3.2.1
func GlobalRestoreBytesBufferAlloc()
Global setting
func GuardThreadsOrDefault ¶ added in v3.2.1
GuardThreads on caller
func HasExecutionContext ¶ added in v3.4.8
HasExecutionID checks if the context has an execution ID
func InitHeadless ¶
InitHeadless initializes headless protocol state
func IsHostAllowed ¶
IsHostAllowed checks if the host is allowed by network policy
func IsLfaAllowed ¶ added in v3.4.8
IsLfaAllowed returns whether local file access is allowed
func IsLowOnMemory ¶ added in v3.2.1
func IsLowOnMemory() bool
func IsRestrictLocalNetworkAccess ¶ added in v3.4.8
func NewJSRuntime ¶
NewJSRuntime returns a new javascript runtime with defaults set i.e sourcemap parsing is disabled by default
func NormalizePath ¶
Normalizepath normalizes path and returns absolute path it returns error if path is not allowed this respects the sandbox rules and only loads files from allowed directories
func NormalizePathWithExecutionId ¶ added in v3.4.8
func SetLfaAllowed ¶ added in v3.4.8
func ShouldInit ¶ added in v3.2.9
func StartActiveMemGuardian ¶ added in v3.2.1
func StopActiveMemGuardian ¶ added in v3.2.1
func StopActiveMemGuardian()
func ValidateNFailRequest ¶
func ValidateNFailRequest(options *types.Options, page *rod.Page, e *proto.FetchRequestPaused) error
ValidateNFailRequest validates and fails request if the request does not respect the rules, it will be canceled with reason
func WithAutoExecutionContext ¶ added in v3.4.8
WithAutoExecutionContext creates a new context with an automatically generated execution ID If the input context already has an execution ID, it will be preserved
func WithExecutionID ¶ added in v3.4.8
func WithExecutionID(ctx context.Context, executionContext *ExecutionContext) context.Context
WithExecutionID adds an execution ID to the context
Types ¶
type Dialers ¶ added in v3.4.8
type Dialers struct {
Fastdialer *fastdialer.Dialer
RawHTTPClient *rawhttp.Client
DefaultHTTPClient *retryablehttp.Client
HTTPClientPool *HTTPPool
PerHostRateLimitPool any // *httpclientpool.PerHostRateLimitPool
HTTPToHTTPSPortTracker any // *httpclientpool.HTTPToHTTPSPortTracker
NetworkPolicy *networkpolicy.NetworkPolicy
LocalFileAccessAllowed bool
RestrictLocalNetworkAccess bool
sync.Mutex
}
func GetDialers ¶ added in v3.4.8
func GetDialersWithId ¶ added in v3.4.8
type ExecutionContext ¶ added in v3.4.8
type ExecutionContext struct {
ExecutionID string
}
func GetExecutionContext ¶ added in v3.4.8
func GetExecutionContext(ctx context.Context) *ExecutionContext
GetExecutionID retrieves the execution ID from the context Returns empty string if no execution ID is set
type HTTPPool ¶ added in v3.10.0
type HTTPPool struct {
// contains filtered or unexported fields
}
HTTPPool is a two-level cache for retryablehttp clients and the http.RoundTripper transports they share.
Design goals (hot path = one lookup per outgoing request):
- lock-free cache hits: sync.Map reads plus atomic last-access updates, no global mutex acquisition per request
- singleflight creation: concurrent first requests to the same key build exactly one client/transport instead of N-1 orphans holding sockets
- transport/client split: client-level settings (redirect policy, cookie jar, timeout) get their own cheap client wrapper while sharing one transport (and therefore one connection pool) per host
- eviction closes connections: idle transports get CloseIdleConnections() instead of being silently dropped for the GC to find
func NewHTTPPool ¶ added in v3.10.0
NewHTTPPool creates a pool whose entries are evicted after the given inactivity duration, checked lazily at most once per cleanupInterval.
func (*HTTPPool) Close ¶ added in v3.10.0
func (p *HTTPPool) Close()
Close drops all cached clients and transports, closing idle connections so no transport goroutines linger after shutdown.
func (*HTTPPool) GetClient ¶ added in v3.10.0
func (p *HTTPPool) GetClient(key string) (*retryablehttp.Client, bool)
GetClient returns a cached client for the key, refreshing its eviction timestamp. The hit path performs no locking.
func (*HTTPPool) GetOrCreateClient ¶ added in v3.10.0
func (p *HTTPPool) GetOrCreateClient( clientKey, transportKey string, createTransport func() (http.RoundTripper, error), createClient func(rt http.RoundTripper) (*retryablehttp.Client, error), ) (*retryablehttp.Client, error)
GetOrCreateClient returns the cached client for clientKey or builds it exactly once (singleflight) using a transport shared via transportKey.
func (*HTTPPool) GetOrCreateTransport ¶ added in v3.10.0
func (p *HTTPPool) GetOrCreateTransport(key string, create func() (http.RoundTripper, error)) (http.RoundTripper, error)
GetOrCreateTransport returns the shared transport for the key, building it exactly once. Used directly by callers that need an uncached client (e.g. explicit per-request cookie jars) but still want pooled connections.