UNPKG

lightweight-browser-load-tester

Version:

A lightweight load testing tool using real browsers for streaming applications with DRM support

173 lines 4.62 kB
import { Page } from 'playwright'; import { ParameterTemplate, NetworkMetrics, ErrorLog, StreamingMetrics, StreamingError } from '../types'; /** * Variable context for parameter template substitution */ export interface VariableContext { sessionId: string; timestamp: number; requestCount: number; [key: string]: any; } /** * Intercepted request data for modification */ export interface InterceptedRequest { url: string; method: string; headers: Record<string, string>; postData?: string; } /** * Request interception result */ export interface InterceptionResult { modified: boolean; originalUrl: string; modifiedUrl?: string; originalHeaders: Record<string, string>; modifiedHeaders?: Record<string, string>; originalPostData?: string; modifiedPostData?: string; } /** * Network request interceptor that modifies requests based on parameter templates */ export declare class RequestInterceptor { private page; private parameterTemplates; private variableContext; private networkMetrics; private errors; private streamingErrors; private requestCount; private streamingStartTime; private streamingOnly; private blockedRequestCount; private allowedUrls; private blockedUrls; private fileDataCache; private randomizationUtil; constructor(page: Page, parameterTemplates?: ParameterTemplate[], initialContext?: Partial<VariableContext>, streamingOnly?: boolean, allowedUrls?: string[], blockedUrls?: string[]); /** * Start intercepting network requests */ startInterception(): Promise<void>; /** * Stop intercepting network requests */ stopInterception(): Promise<void>; /** * Update variable context for parameter substitution */ updateContext(updates: Partial<VariableContext>): void; /** * Get collected network metrics */ getNetworkMetrics(): NetworkMetrics[]; /** * Get collected errors */ getErrors(): ErrorLog[]; /** * Get streaming-specific errors */ getStreamingErrors(): StreamingError[]; /** * Get the number of blocked requests (when streamingOnly is enabled) */ getBlockedRequestCount(): number; /** * Get aggregated streaming metrics */ getStreamingMetrics(): StreamingMetrics; /** * Start streaming monitoring (marks the beginning of streaming test) */ startStreamingMonitoring(): void; /** * Clear collected metrics and errors */ clearMetrics(): void; /** * Handle intercepted request */ private handleRequest; /** * Modify request based on parameter templates */ private modifyRequest; /** * Substitute variables in template string with support for random functions */ private substituteVariables; /** * Add query parameter to URL */ private addQueryParameter; /** * Modify request body (supports JSON and form data) */ private modifyRequestBody; /** * Check if string looks like form data */ private isFormData; /** * Collect network metrics from response */ private collectNetworkMetrics; /** * Calculate approximate request size */ private calculateRequestSize; /** * Log request failure */ private logRequestFailure; /** * Calculate approximate response size */ private calculateResponseSize; /** * Check if request is streaming-related */ private isStreamingRequest; /** * Check if request is essential for page functionality (should not be blocked even in streaming-only mode) */ private isEssentialRequest; /** * Check if URL matches any of the allowed URL patterns */ private isAllowedUrl; /** * Check if URL matches any of the blocked URL patterns */ private isBlockedUrl; /** * Check if URL matches a pattern (supports wildcards and regex-like patterns) */ private matchesUrlPattern; /** * Check if a parameter template should be applied to a specific request */ private shouldApplyTemplate; /** * Determine streaming request type */ private getStreamingType; /** * Calculate average response time for a set of metrics */ private calculateAverageResponseTime; /** * Log streaming-specific error */ private logStreamingError; /** * Log error with context */ private logError; } //# sourceMappingURL=request-interceptor.d.ts.map