@xbrowser/cli 1.27.0 → 1.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{browser-NYYCR4O7.js → browser-2K3XYAKM.js} +5 -3
- package/dist/{browser-ZD53IMUJ.js → browser-OTEMG5NL.js} +6 -4
- package/dist/{browser-4IYIHZ6R.js → browser-XD3IOU5I.js} +8 -6
- package/dist/{cdp-driver-EFEW4ZEN.js → cdp-driver-AAS55KT2.js} +4 -4
- package/dist/{cdp-driver-4X6Q62WI.js → cdp-driver-O5I7SJ24.js} +3 -3
- package/dist/{cdp-driver-HB744QB4.js → cdp-driver-XTPY7EXP.js} +1296 -852
- package/dist/{chunk-SEEWE5SJ.js → chunk-2KPI5GKP.js} +3 -0
- package/dist/{chunk-75DNUI6M.js → chunk-6UJU2FJK.js} +146 -0
- package/dist/{chunk-3PUOISKE.js → chunk-CO2ZVOVT.js} +496 -452
- package/dist/{chunk-V6KGBU5J.js → chunk-FCPVQFTQ.js} +1011 -1038
- package/dist/{chunk-IDXOIXQR.js → chunk-GDKKVT2P.js} +773 -655
- package/dist/{chunk-HSYRAV3H.js → chunk-LFSLNHW5.js} +1846 -1358
- package/dist/{chunk-OSZNJT4U.js → chunk-LM32MNBB.js} +79 -8
- package/dist/{chunk-J3HXZVSN.js → chunk-N5XTLNKS.js} +1166 -868
- package/dist/{chunk-T2AI24A5.js → chunk-NAIHOVDZ.js} +3 -0
- package/dist/{chunk-WYETQ5C7.js → chunk-NEE6EMYA.js} +14 -1
- package/dist/{chunk-ME5FO5YV.js → chunk-NQPXZ74W.js} +1296 -852
- package/dist/{chunk-KECYFWJO.js → chunk-P33R7F2D.js} +413 -384
- package/dist/{chunk-YITK42HZ.js → chunk-SCYBNSOG.js} +1596 -1478
- package/dist/{chunk-R3F4K2SB.js → chunk-SMYSNO4M.js} +10 -0
- package/dist/{chunk-IR6C24P7.js → chunk-UZ6XPUBD.js} +1030 -1048
- package/dist/cli.js +3398 -3357
- package/dist/daemon-main.js +749 -700
- package/dist/index.d.ts +362 -474
- package/dist/index.js +5730 -5689
- package/dist/{launcher-SJ44X25U.js → launcher-TOLF23ET.js} +1 -1
- package/dist/{launcher-XHKIC4GP.js → launcher-ZYB32LSZ.js} +1 -1
- package/dist/{plugin-singleton-GGSBI3EG.js → plugin-singleton-A6RNITJW.js} +1 -1
- package/dist/{proxy-NKCYE76M.js → proxy-H3RIUOCN.js} +2 -2
- package/dist/{server-YKMRFDEM.js → server-LNZTDAKT.js} +4 -4
- package/dist/{server-WDDGIV3C.js → server-ZTI2K5YJ.js} +7 -7
- package/dist/{session-recorder-GEZVQBKW.js → session-recorder-DF2YGH2E.js} +1 -1
- package/dist/{session-recorder-563ISSJK.js → session-recorder-R3GDGXLJ.js} +1 -1
- package/dist/{session-replayer-TXTNTG33.js → session-replayer-CLTZ2URU.js} +1 -1
- package/dist/{stealth-QNSMIHQK.js → stealth-FMPZO2OB.js} +1 -1
- package/dist/{stealth-MHJNBJY7.js → stealth-MCKFKPZ6.js} +1 -1
- package/package.json +6 -3
package/dist/index.d.ts
CHANGED
|
@@ -6,6 +6,40 @@ import { ZodType, ZodTypeDef, z } from 'zod';
|
|
|
6
6
|
|
|
7
7
|
declare const version: any;
|
|
8
8
|
|
|
9
|
+
interface HookOutput {
|
|
10
|
+
_hook: string;
|
|
11
|
+
[key: string]: unknown;
|
|
12
|
+
}
|
|
13
|
+
interface ExecutionResult {
|
|
14
|
+
success: boolean;
|
|
15
|
+
data: unknown;
|
|
16
|
+
message?: string;
|
|
17
|
+
duration: number;
|
|
18
|
+
tips?: Tip[];
|
|
19
|
+
hookOutputs?: HookOutput[];
|
|
20
|
+
error?: {
|
|
21
|
+
code: string;
|
|
22
|
+
level: string;
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
interface ChainStepResult {
|
|
26
|
+
command: string;
|
|
27
|
+
raw: string;
|
|
28
|
+
success: boolean;
|
|
29
|
+
data: unknown;
|
|
30
|
+
message?: string;
|
|
31
|
+
duration: number;
|
|
32
|
+
tips?: Tip[];
|
|
33
|
+
hookOutputs?: HookOutput[];
|
|
34
|
+
}
|
|
35
|
+
interface ChainExecutionResult {
|
|
36
|
+
success: boolean;
|
|
37
|
+
steps: ChainStepResult[];
|
|
38
|
+
totalDuration: number;
|
|
39
|
+
stoppedAt?: number;
|
|
40
|
+
stoppedReason?: string;
|
|
41
|
+
}
|
|
42
|
+
|
|
9
43
|
/**
|
|
10
44
|
* stealth.ts — Behavioral stealth layer for CDP driver
|
|
11
45
|
*
|
|
@@ -551,6 +585,210 @@ interface XBRequest {
|
|
|
551
585
|
response(): Promise<XBResponse | null>;
|
|
552
586
|
}
|
|
553
587
|
|
|
588
|
+
/**
|
|
589
|
+
* CDP Interceptor — Core Types
|
|
590
|
+
*
|
|
591
|
+
* Models the JSON-RPC 2.0 messages flowing over the CDP WebSocket and
|
|
592
|
+
* defines the rule/decision system for intercepting, blocking, or
|
|
593
|
+
* transforming automation traffic to avoid anti-crawler detection.
|
|
594
|
+
*/
|
|
595
|
+
/** Raw JSON-RPC 2.0 request as it appears on the wire */
|
|
596
|
+
interface CDPRequest {
|
|
597
|
+
id: number;
|
|
598
|
+
method: string;
|
|
599
|
+
params?: Record<string, unknown>;
|
|
600
|
+
sessionId?: string;
|
|
601
|
+
}
|
|
602
|
+
/** Raw JSON-RPC 2.0 response (success) */
|
|
603
|
+
interface CDPResponse {
|
|
604
|
+
id: number;
|
|
605
|
+
result?: Record<string, unknown>;
|
|
606
|
+
sessionId?: string;
|
|
607
|
+
}
|
|
608
|
+
/** Raw JSON-RPC 2.0 error response */
|
|
609
|
+
interface CDPError {
|
|
610
|
+
id: number;
|
|
611
|
+
error: {
|
|
612
|
+
code: number;
|
|
613
|
+
message: string;
|
|
614
|
+
data?: unknown;
|
|
615
|
+
};
|
|
616
|
+
sessionId?: string;
|
|
617
|
+
}
|
|
618
|
+
/** Union of all possible CDP messages */
|
|
619
|
+
type CDPMessage = CDPRequest | CDPResponse | CDPError;
|
|
620
|
+
/** Direction: from client → browser or browser → client */
|
|
621
|
+
type MessageDirection = 'client→browser' | 'browser→client';
|
|
622
|
+
/** Structured log entry for a single CDP message */
|
|
623
|
+
interface CDPLogEntry {
|
|
624
|
+
/** Unix timestamp in ms */
|
|
625
|
+
timestamp: number;
|
|
626
|
+
/** Message direction */
|
|
627
|
+
direction: MessageDirection;
|
|
628
|
+
/** Session identifier (for grouping messages) */
|
|
629
|
+
sessionId: string;
|
|
630
|
+
/** CDP method (e.g. "Runtime.evaluate"), undefined for responses */
|
|
631
|
+
method?: string;
|
|
632
|
+
/** Sanitized payload summary */
|
|
633
|
+
payload: Record<string, unknown>;
|
|
634
|
+
/** Rule decision that was applied, if any */
|
|
635
|
+
decision?: DecisionResult;
|
|
636
|
+
}
|
|
637
|
+
/**
|
|
638
|
+
* Severity of a rule violation
|
|
639
|
+
*
|
|
640
|
+
* - **danger**: definitely triggers anti-crawler detection — block immediately
|
|
641
|
+
* - **warn**: likely problematic — log and warn, but don't block yet
|
|
642
|
+
* - **info**: informational only — could be a future concern
|
|
643
|
+
*/
|
|
644
|
+
type ViolationSeverity = 'danger' | 'warn' | 'info';
|
|
645
|
+
/**
|
|
646
|
+
* Action the interceptor should take for a matched message
|
|
647
|
+
*
|
|
648
|
+
* - **block**: reject the message, return CDP error, never reach browser
|
|
649
|
+
* - **transform**: modify the message before forwarding
|
|
650
|
+
* - **pass**: forward unchanged (log only)
|
|
651
|
+
*/
|
|
652
|
+
type DecisionAction = 'block' | 'transform' | 'pass';
|
|
653
|
+
/** Result of a rule evaluation */
|
|
654
|
+
interface DecisionResult {
|
|
655
|
+
/** Matched rule id */
|
|
656
|
+
ruleId: string;
|
|
657
|
+
action: DecisionAction;
|
|
658
|
+
severity: ViolationSeverity;
|
|
659
|
+
/** Human-readable explanation of why this was flagged */
|
|
660
|
+
reason: string;
|
|
661
|
+
/** Suggested fix / alternative approach */
|
|
662
|
+
suggestion?: string;
|
|
663
|
+
/** Transformed params (only for 'transform' action) */
|
|
664
|
+
transformedParams?: Record<string, unknown>;
|
|
665
|
+
/** Custom CDP error code (only for 'block' action) */
|
|
666
|
+
errorCode?: number;
|
|
667
|
+
/** Custom CDP error message (only for 'block' action) */
|
|
668
|
+
errorMessage?: string;
|
|
669
|
+
}
|
|
670
|
+
/** Handler context passed to each rule */
|
|
671
|
+
interface RuleContext {
|
|
672
|
+
method: string;
|
|
673
|
+
params: Record<string, unknown>;
|
|
674
|
+
sessionId: string;
|
|
675
|
+
/** Direction: the message is being sent TO the browser */
|
|
676
|
+
direction: MessageDirection;
|
|
677
|
+
/** Per-session state store (rules can stash data here) */
|
|
678
|
+
sessionState: Map<string, unknown>;
|
|
679
|
+
}
|
|
680
|
+
/**
|
|
681
|
+
* A CDP interception rule
|
|
682
|
+
*
|
|
683
|
+
* Rules are evaluated **in priority order** (lower number = earlier).
|
|
684
|
+
* The first rule that returns a decision wins.
|
|
685
|
+
*/
|
|
686
|
+
interface CDPInterceptorRule {
|
|
687
|
+
/** Unique rule identifier */
|
|
688
|
+
id: string;
|
|
689
|
+
/** Human-readable name */
|
|
690
|
+
name: string;
|
|
691
|
+
/** Priority: lower numbers are evaluated first */
|
|
692
|
+
priority: number;
|
|
693
|
+
/**
|
|
694
|
+
* Quick pre-filter — skip expensive checks for messages that can't match.
|
|
695
|
+
* Return false to skip this rule.
|
|
696
|
+
*/
|
|
697
|
+
canHandle?(ctx: RuleContext): boolean;
|
|
698
|
+
/**
|
|
699
|
+
* Evaluate the message and return a decision.
|
|
700
|
+
* Return null to pass (no match).
|
|
701
|
+
*/
|
|
702
|
+
evaluate(ctx: RuleContext): DecisionResult | null;
|
|
703
|
+
}
|
|
704
|
+
/** Configuration for the CDP interceptor proxy */
|
|
705
|
+
interface CDPInterceptorConfig {
|
|
706
|
+
/** Chromium CDP WebSocket endpoint (e.g. ws://localhost:9222/...) */
|
|
707
|
+
cdpEndpoint: string;
|
|
708
|
+
/** Port to listen on for incoming client connections */
|
|
709
|
+
listenPort?: number;
|
|
710
|
+
/** Rules to apply, defaults to built-in rules */
|
|
711
|
+
rules?: CDPInterceptorRule[];
|
|
712
|
+
/** Enable logging (default: true) */
|
|
713
|
+
enableLogging?: boolean;
|
|
714
|
+
/** Log output directory (default: no file logging) */
|
|
715
|
+
logDir?: string;
|
|
716
|
+
/** Block mode: 'strict' blocks danger only, 'paranoid' blocks warn+ */
|
|
717
|
+
blockMode?: 'strict' | 'paranoid';
|
|
718
|
+
}
|
|
719
|
+
/** Statistics collected during a proxy session */
|
|
720
|
+
interface CDPInterceptorStats {
|
|
721
|
+
totalMessages: number;
|
|
722
|
+
blockedMessages: number;
|
|
723
|
+
transformedMessages: number;
|
|
724
|
+
passedMessages: number;
|
|
725
|
+
/** Breakdown by rule id */
|
|
726
|
+
byRule: Record<string, {
|
|
727
|
+
matched: number;
|
|
728
|
+
blocked: number;
|
|
729
|
+
transformed: number;
|
|
730
|
+
}>;
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
interface ManagedSession {
|
|
734
|
+
id: string;
|
|
735
|
+
name: string;
|
|
736
|
+
context: XBContext;
|
|
737
|
+
page: XBPage;
|
|
738
|
+
browser: XBBrowser;
|
|
739
|
+
createdAt: string;
|
|
740
|
+
lastActivityAt: number;
|
|
741
|
+
isCDP?: boolean;
|
|
742
|
+
cdpEndpoint?: string;
|
|
743
|
+
}
|
|
744
|
+
interface BrowserLaunchOptions {
|
|
745
|
+
headless?: boolean;
|
|
746
|
+
executablePath?: string;
|
|
747
|
+
cdpEndpoint?: string;
|
|
748
|
+
intercept?: boolean | CDPInterceptorConfig;
|
|
749
|
+
}
|
|
750
|
+
|
|
751
|
+
/**
|
|
752
|
+
* CDP Interceptor Proxy
|
|
753
|
+
*
|
|
754
|
+
* A thin WebSocket proxy that sits between any automation tool (Playwright,
|
|
755
|
+
* Puppeteer, etc.) and Chromium's CDP endpoint. Every JSON-RPC message is
|
|
756
|
+
* intercepted, analyzed against a rule engine, and either passed through,
|
|
757
|
+
* blocked (with error response), or transformed before reaching the browser.
|
|
758
|
+
*
|
|
759
|
+
* Usage:
|
|
760
|
+
* ```
|
|
761
|
+
* const proxy = new CDPInterceptorProxy({ cdpEndpoint: 'ws://localhost:9222/...' });
|
|
762
|
+
* await proxy.start(); // starts listening on a random port
|
|
763
|
+
* // Now connect your automation tool to: ws://localhost:{proxy.port}
|
|
764
|
+
* ```
|
|
765
|
+
*/
|
|
766
|
+
|
|
767
|
+
declare class CDPInterceptorProxy {
|
|
768
|
+
private wss;
|
|
769
|
+
private engine;
|
|
770
|
+
private config;
|
|
771
|
+
private logger;
|
|
772
|
+
private started;
|
|
773
|
+
stats: CDPInterceptorStats;
|
|
774
|
+
constructor(config: CDPInterceptorConfig);
|
|
775
|
+
/** The port the proxy is listening on (only valid after start()) */
|
|
776
|
+
get port(): number;
|
|
777
|
+
/** Start the proxy server */
|
|
778
|
+
start(): Promise<number>;
|
|
779
|
+
/** Stop the proxy server */
|
|
780
|
+
stop(): Promise<void>;
|
|
781
|
+
/** Get accumulated statistics */
|
|
782
|
+
getStats(): CDPInterceptorStats;
|
|
783
|
+
/** Get recent log entries (for inspection) */
|
|
784
|
+
getRecentLogs(count?: number): CDPLogEntry[];
|
|
785
|
+
private handleConnection;
|
|
786
|
+
private handleClientMessage;
|
|
787
|
+
private handleBrowserMessage;
|
|
788
|
+
private parseMessage;
|
|
789
|
+
private recordDecision;
|
|
790
|
+
}
|
|
791
|
+
|
|
554
792
|
/**
|
|
555
793
|
* Configuration for the WebSocket server.
|
|
556
794
|
*/
|
|
@@ -733,343 +971,93 @@ interface ScreencastMessage {
|
|
|
733
971
|
id: string;
|
|
734
972
|
timestamp: number;
|
|
735
973
|
data: Buffer;
|
|
736
|
-
url: string;
|
|
737
|
-
viewport: {
|
|
738
|
-
width: number;
|
|
739
|
-
height: number;
|
|
740
|
-
};
|
|
741
|
-
}
|
|
742
|
-
/**
|
|
743
|
-
* A command execution event message streamed during command lifecycle.
|
|
744
|
-
*/
|
|
745
|
-
interface CommandMessage {
|
|
746
|
-
sessionId: string;
|
|
747
|
-
command: string;
|
|
748
|
-
args: unknown[];
|
|
749
|
-
phase: 'before' | 'after';
|
|
750
|
-
result?: unknown;
|
|
751
|
-
error?: string;
|
|
752
|
-
timestamp: number;
|
|
753
|
-
duration?: number;
|
|
754
|
-
}
|
|
755
|
-
/**
|
|
756
|
-
* A server status change notification.
|
|
757
|
-
*/
|
|
758
|
-
interface StatusMessage {
|
|
759
|
-
status: 'connected' | 'disconnected' | 'error';
|
|
760
|
-
sessionId?: string;
|
|
761
|
-
message?: string;
|
|
762
|
-
viewport?: {
|
|
763
|
-
width: number;
|
|
764
|
-
height: number;
|
|
765
|
-
};
|
|
766
|
-
}
|
|
767
|
-
/**
|
|
768
|
-
* WebSocket server for streaming browser screenshots and handling remote input.
|
|
769
|
-
*
|
|
770
|
-
* Two modes:
|
|
771
|
-
* 1. **Standalone**: `start()` creates its own WS server on a port.
|
|
772
|
-
* 2. **Attached**: `attachToServer(httpServer)` shares an existing HTTP server
|
|
773
|
-
* via the WS upgrade mechanism (same port as HTTP, e.g., daemon port 9224).
|
|
774
|
-
*
|
|
775
|
-
* **Lazy screencast**: Screencast capture only starts when the first WS client
|
|
776
|
-
* binds to a session, and stops when the last client for that session disconnects.
|
|
777
|
-
*
|
|
778
|
-
* Responsibilities are delegated to:
|
|
779
|
-
* - **SessionManager**: client/session lifecycle, capturer start/stop, element monitors
|
|
780
|
-
* - **StreamCoordinator**: frame processing, stream state, crop management
|
|
781
|
-
* - **MessageDispatcher**: inbound message routing to typed handlers
|
|
782
|
-
*/
|
|
783
|
-
declare class WSServer extends EventEmitter {
|
|
784
|
-
private port;
|
|
785
|
-
private host;
|
|
786
|
-
private wsServer;
|
|
787
|
-
private isRunning;
|
|
788
|
-
private readonly streamCoordinator;
|
|
789
|
-
private readonly sessionManager;
|
|
790
|
-
private readonly messageDispatcher;
|
|
791
|
-
constructor(config?: WSServerConfig);
|
|
792
|
-
private setupSessionManagerEvents;
|
|
793
|
-
registerSession(sessionId: string, page: XBPage, options?: {
|
|
794
|
-
interval?: number;
|
|
795
|
-
quality?: number;
|
|
796
|
-
type?: 'jpeg' | 'png';
|
|
797
|
-
width?: number;
|
|
798
|
-
height?: number;
|
|
799
|
-
}): void;
|
|
800
|
-
/** Restart screencast for a session — used by viewer reconnect button. */
|
|
801
|
-
reconnectSession(sessionId: string): Promise<void>;
|
|
802
|
-
unregisterSession(sessionId: string): void;
|
|
803
|
-
pauseScreencast(sessionId: string): Promise<void>;
|
|
804
|
-
resumeScreencast(sessionId: string): Promise<void>;
|
|
805
|
-
private startScreencastIfNeeded;
|
|
806
|
-
private stopScreencastIfNeeded;
|
|
807
|
-
bindClientToSession(clientId: string, sessionId: string): void;
|
|
808
|
-
private sendBoundStatus;
|
|
809
|
-
start(): Promise<void>;
|
|
810
|
-
attachToServer(httpServer: Server, path?: string): Promise<void>;
|
|
811
|
-
stop(): Promise<void>;
|
|
812
|
-
private setupConnectionHandler;
|
|
813
|
-
private handleInboundMessage;
|
|
814
|
-
private handleClientDisconnect;
|
|
815
|
-
private sendToClient;
|
|
816
|
-
broadcastToSession(sessionId: string, message: WSMessage): void;
|
|
817
|
-
broadcast(message: WSMessage): void;
|
|
818
|
-
broadcastBinaryToSession(sessionId: string, payload: Buffer): void;
|
|
819
|
-
getClientCount(): number;
|
|
820
|
-
getSessionClientCount(sessionId: string): number;
|
|
821
|
-
getRunning(): boolean;
|
|
822
|
-
getPort(): number;
|
|
823
|
-
}
|
|
824
|
-
|
|
825
|
-
/**
|
|
826
|
-
* Result of a single command execution.
|
|
827
|
-
*/
|
|
828
|
-
interface HookOutput {
|
|
829
|
-
_hook: string;
|
|
830
|
-
[key: string]: unknown;
|
|
831
|
-
}
|
|
832
|
-
interface ExecutionResult {
|
|
833
|
-
success: boolean;
|
|
834
|
-
data: unknown;
|
|
835
|
-
message?: string;
|
|
836
|
-
duration: number;
|
|
837
|
-
tips?: Tip[];
|
|
838
|
-
hookOutputs?: HookOutput[];
|
|
839
|
-
error?: {
|
|
840
|
-
code: string;
|
|
841
|
-
level: string;
|
|
842
|
-
};
|
|
843
|
-
}
|
|
844
|
-
/**
|
|
845
|
-
* Result of a single step within a command chain execution.
|
|
846
|
-
*/
|
|
847
|
-
interface ChainStepResult {
|
|
848
|
-
command: string;
|
|
849
|
-
raw: string;
|
|
850
|
-
success: boolean;
|
|
851
|
-
data: unknown;
|
|
852
|
-
message?: string;
|
|
853
|
-
duration: number;
|
|
854
|
-
tips?: Tip[];
|
|
855
|
-
hookOutputs?: HookOutput[];
|
|
856
|
-
}
|
|
857
|
-
/**
|
|
858
|
-
* Result of executing a command chain (multiple commands linked with &&, ||, etc.).
|
|
859
|
-
*/
|
|
860
|
-
interface ChainExecutionResult {
|
|
861
|
-
success: boolean;
|
|
862
|
-
steps: ChainStepResult[];
|
|
863
|
-
totalDuration: number;
|
|
864
|
-
stoppedAt?: number;
|
|
865
|
-
stoppedReason?: string;
|
|
866
|
-
}
|
|
867
|
-
/**
|
|
868
|
-
* Set or clear the WebSocket server used for streaming command events.
|
|
869
|
-
*
|
|
870
|
-
* @param server - A WSServer instance to stream events to, or null to disable.
|
|
871
|
-
*/
|
|
872
|
-
declare function setWSServer(server: WSServer | null): void;
|
|
873
|
-
/**
|
|
874
|
-
* Execute a single browser command against an existing session.
|
|
875
|
-
*
|
|
876
|
-
* Looks up the command by name, validates parameters via Zod schema,
|
|
877
|
-
* resolves the target session, and runs the command handler.
|
|
878
|
-
* Streams before/after events to the configured WebSocket server.
|
|
879
|
-
*
|
|
880
|
-
* @param commandName - Registered command name (e.g. "goto", "click", "fill").
|
|
881
|
-
* @param params - Key-value parameters forwarded to the command handler.
|
|
882
|
-
* @param sessionName - Name of the target session. Defaults to "default".
|
|
883
|
-
* @returns An {@link ExecutionResult} with success status, data, and duration.
|
|
884
|
-
*
|
|
885
|
-
* @example
|
|
886
|
-
* ```ts
|
|
887
|
-
* const result = await executeCommand('click', { selector: '#submit' }, 'default');
|
|
888
|
-
* if (result.success) console.log('Clicked!', result.data);
|
|
889
|
-
* ```
|
|
890
|
-
*/
|
|
891
|
-
declare function executeCommand(commandName: string, params: Record<string, unknown>, sessionName?: string, extraOpts?: {
|
|
892
|
-
cdpEndpoint?: string;
|
|
893
|
-
skipCleanup?: boolean;
|
|
894
|
-
timeout?: number;
|
|
895
|
-
_recoveryAttempted?: boolean;
|
|
896
|
-
}): Promise<ExecutionResult>;
|
|
897
|
-
/**
|
|
898
|
-
* Execute a chain of browser commands parsed from a string expression.
|
|
899
|
-
*
|
|
900
|
-
* Supports `&&` (and-chain, stops on first failure), `||` (or-chain, stops on
|
|
901
|
-
* first success), `;` (sequence separator), `->`, `,`, and `+` operators.
|
|
902
|
-
* Automatically creates a browser session if none exists and destroys it
|
|
903
|
-
* afterwards.
|
|
904
|
-
*
|
|
905
|
-
* @param input - Raw chain expression (e.g. `"goto https://example.com && click #btn"`).
|
|
906
|
-
* @param options - Optional configuration for CDP endpoint, session name, and file mode.
|
|
907
|
-
* @returns A {@link ChainExecutionResult} with per-step results and total duration.
|
|
908
|
-
*
|
|
909
|
-
* @example
|
|
910
|
-
* ```ts
|
|
911
|
-
* const result = await executeChain('goto https://example.com && click #btn');
|
|
912
|
-
* console.log(result.success, result.steps.length);
|
|
913
|
-
* ```
|
|
914
|
-
*/
|
|
915
|
-
declare function executeChain(input: string, options?: {
|
|
916
|
-
cdpEndpoint?: string;
|
|
917
|
-
sessionName?: string;
|
|
918
|
-
fileMode?: boolean;
|
|
919
|
-
}): Promise<ChainExecutionResult>;
|
|
920
|
-
/**
|
|
921
|
-
* Check whether the given input string contains chain operators.
|
|
922
|
-
*
|
|
923
|
-
* Detects `&&`, `;`, `,`, `+`, and `->` surrounded by whitespace.
|
|
924
|
-
*
|
|
925
|
-
* @param input - The raw input string to test.
|
|
926
|
-
* @returns `true` if chain operators are present.
|
|
927
|
-
*/
|
|
928
|
-
declare function isChainInput(input: string): boolean;
|
|
929
|
-
|
|
930
|
-
/**
|
|
931
|
-
* CDP Interceptor — Core Types
|
|
932
|
-
*
|
|
933
|
-
* Models the JSON-RPC 2.0 messages flowing over the CDP WebSocket and
|
|
934
|
-
* defines the rule/decision system for intercepting, blocking, or
|
|
935
|
-
* transforming automation traffic to avoid anti-crawler detection.
|
|
936
|
-
*/
|
|
937
|
-
/** Raw JSON-RPC 2.0 request as it appears on the wire */
|
|
938
|
-
interface CDPRequest {
|
|
939
|
-
id: number;
|
|
940
|
-
method: string;
|
|
941
|
-
params?: Record<string, unknown>;
|
|
942
|
-
sessionId?: string;
|
|
943
|
-
}
|
|
944
|
-
/** Raw JSON-RPC 2.0 response (success) */
|
|
945
|
-
interface CDPResponse {
|
|
946
|
-
id: number;
|
|
947
|
-
result?: Record<string, unknown>;
|
|
948
|
-
sessionId?: string;
|
|
949
|
-
}
|
|
950
|
-
/** Raw JSON-RPC 2.0 error response */
|
|
951
|
-
interface CDPError {
|
|
952
|
-
id: number;
|
|
953
|
-
error: {
|
|
954
|
-
code: number;
|
|
955
|
-
message: string;
|
|
956
|
-
data?: unknown;
|
|
957
|
-
};
|
|
958
|
-
sessionId?: string;
|
|
959
|
-
}
|
|
960
|
-
/** Union of all possible CDP messages */
|
|
961
|
-
type CDPMessage = CDPRequest | CDPResponse | CDPError;
|
|
962
|
-
/** Direction: from client → browser or browser → client */
|
|
963
|
-
type MessageDirection = 'client→browser' | 'browser→client';
|
|
964
|
-
/** Structured log entry for a single CDP message */
|
|
965
|
-
interface CDPLogEntry {
|
|
966
|
-
/** Unix timestamp in ms */
|
|
967
|
-
timestamp: number;
|
|
968
|
-
/** Message direction */
|
|
969
|
-
direction: MessageDirection;
|
|
970
|
-
/** Session identifier (for grouping messages) */
|
|
971
|
-
sessionId: string;
|
|
972
|
-
/** CDP method (e.g. "Runtime.evaluate"), undefined for responses */
|
|
973
|
-
method?: string;
|
|
974
|
-
/** Sanitized payload summary */
|
|
975
|
-
payload: Record<string, unknown>;
|
|
976
|
-
/** Rule decision that was applied, if any */
|
|
977
|
-
decision?: DecisionResult;
|
|
978
|
-
}
|
|
979
|
-
/**
|
|
980
|
-
* Severity of a rule violation
|
|
981
|
-
*
|
|
982
|
-
* - **danger**: definitely triggers anti-crawler detection — block immediately
|
|
983
|
-
* - **warn**: likely problematic — log and warn, but don't block yet
|
|
984
|
-
* - **info**: informational only — could be a future concern
|
|
985
|
-
*/
|
|
986
|
-
type ViolationSeverity = 'danger' | 'warn' | 'info';
|
|
987
|
-
/**
|
|
988
|
-
* Action the interceptor should take for a matched message
|
|
989
|
-
*
|
|
990
|
-
* - **block**: reject the message, return CDP error, never reach browser
|
|
991
|
-
* - **transform**: modify the message before forwarding
|
|
992
|
-
* - **pass**: forward unchanged (log only)
|
|
993
|
-
*/
|
|
994
|
-
type DecisionAction = 'block' | 'transform' | 'pass';
|
|
995
|
-
/** Result of a rule evaluation */
|
|
996
|
-
interface DecisionResult {
|
|
997
|
-
/** Matched rule id */
|
|
998
|
-
ruleId: string;
|
|
999
|
-
action: DecisionAction;
|
|
1000
|
-
severity: ViolationSeverity;
|
|
1001
|
-
/** Human-readable explanation of why this was flagged */
|
|
1002
|
-
reason: string;
|
|
1003
|
-
/** Suggested fix / alternative approach */
|
|
1004
|
-
suggestion?: string;
|
|
1005
|
-
/** Transformed params (only for 'transform' action) */
|
|
1006
|
-
transformedParams?: Record<string, unknown>;
|
|
1007
|
-
/** Custom CDP error code (only for 'block' action) */
|
|
1008
|
-
errorCode?: number;
|
|
1009
|
-
/** Custom CDP error message (only for 'block' action) */
|
|
1010
|
-
errorMessage?: string;
|
|
1011
|
-
}
|
|
1012
|
-
/** Handler context passed to each rule */
|
|
1013
|
-
interface RuleContext {
|
|
1014
|
-
method: string;
|
|
1015
|
-
params: Record<string, unknown>;
|
|
1016
|
-
sessionId: string;
|
|
1017
|
-
/** Direction: the message is being sent TO the browser */
|
|
1018
|
-
direction: MessageDirection;
|
|
1019
|
-
/** Per-session state store (rules can stash data here) */
|
|
1020
|
-
sessionState: Map<string, unknown>;
|
|
974
|
+
url: string;
|
|
975
|
+
viewport: {
|
|
976
|
+
width: number;
|
|
977
|
+
height: number;
|
|
978
|
+
};
|
|
1021
979
|
}
|
|
1022
980
|
/**
|
|
1023
|
-
* A
|
|
1024
|
-
*
|
|
1025
|
-
* Rules are evaluated **in priority order** (lower number = earlier).
|
|
1026
|
-
* The first rule that returns a decision wins.
|
|
981
|
+
* A command execution event message streamed during command lifecycle.
|
|
1027
982
|
*/
|
|
1028
|
-
interface
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
* Return false to skip this rule.
|
|
1038
|
-
*/
|
|
1039
|
-
canHandle?(ctx: RuleContext): boolean;
|
|
1040
|
-
/**
|
|
1041
|
-
* Evaluate the message and return a decision.
|
|
1042
|
-
* Return null to pass (no match).
|
|
1043
|
-
*/
|
|
1044
|
-
evaluate(ctx: RuleContext): DecisionResult | null;
|
|
983
|
+
interface CommandMessage {
|
|
984
|
+
sessionId: string;
|
|
985
|
+
command: string;
|
|
986
|
+
args: unknown[];
|
|
987
|
+
phase: 'before' | 'after';
|
|
988
|
+
result?: unknown;
|
|
989
|
+
error?: string;
|
|
990
|
+
timestamp: number;
|
|
991
|
+
duration?: number;
|
|
1045
992
|
}
|
|
1046
|
-
/**
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
logDir?: string;
|
|
1058
|
-
/** Block mode: 'strict' blocks danger only, 'paranoid' blocks warn+ */
|
|
1059
|
-
blockMode?: 'strict' | 'paranoid';
|
|
993
|
+
/**
|
|
994
|
+
* A server status change notification.
|
|
995
|
+
*/
|
|
996
|
+
interface StatusMessage {
|
|
997
|
+
status: 'connected' | 'disconnected' | 'error';
|
|
998
|
+
sessionId?: string;
|
|
999
|
+
message?: string;
|
|
1000
|
+
viewport?: {
|
|
1001
|
+
width: number;
|
|
1002
|
+
height: number;
|
|
1003
|
+
};
|
|
1060
1004
|
}
|
|
1061
|
-
/**
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1005
|
+
/**
|
|
1006
|
+
* WebSocket server for streaming browser screenshots and handling remote input.
|
|
1007
|
+
*
|
|
1008
|
+
* Two modes:
|
|
1009
|
+
* 1. **Standalone**: `start()` creates its own WS server on a port.
|
|
1010
|
+
* 2. **Attached**: `attachToServer(httpServer)` shares an existing HTTP server
|
|
1011
|
+
* via the WS upgrade mechanism (same port as HTTP, e.g., daemon port 9224).
|
|
1012
|
+
*
|
|
1013
|
+
* **Lazy screencast**: Screencast capture only starts when the first WS client
|
|
1014
|
+
* binds to a session, and stops when the last client for that session disconnects.
|
|
1015
|
+
*
|
|
1016
|
+
* Responsibilities are delegated to:
|
|
1017
|
+
* - **SessionManager**: client/session lifecycle, capturer start/stop, element monitors
|
|
1018
|
+
* - **StreamCoordinator**: frame processing, stream state, crop management
|
|
1019
|
+
* - **MessageDispatcher**: inbound message routing to typed handlers
|
|
1020
|
+
*/
|
|
1021
|
+
declare class WSServer extends EventEmitter {
|
|
1022
|
+
private port;
|
|
1023
|
+
private host;
|
|
1024
|
+
private wsServer;
|
|
1025
|
+
private isRunning;
|
|
1026
|
+
private readonly streamCoordinator;
|
|
1027
|
+
private readonly sessionManager;
|
|
1028
|
+
private readonly messageDispatcher;
|
|
1029
|
+
constructor(config?: WSServerConfig);
|
|
1030
|
+
private setupSessionManagerEvents;
|
|
1031
|
+
registerSession(sessionId: string, page: XBPage, options?: {
|
|
1032
|
+
interval?: number;
|
|
1033
|
+
quality?: number;
|
|
1034
|
+
type?: 'jpeg' | 'png';
|
|
1035
|
+
width?: number;
|
|
1036
|
+
height?: number;
|
|
1037
|
+
}): void;
|
|
1038
|
+
/** Restart screencast for a session — used by viewer reconnect button. */
|
|
1039
|
+
reconnectSession(sessionId: string): Promise<void>;
|
|
1040
|
+
unregisterSession(sessionId: string): void;
|
|
1041
|
+
pauseScreencast(sessionId: string): Promise<void>;
|
|
1042
|
+
resumeScreencast(sessionId: string): Promise<void>;
|
|
1043
|
+
private startScreencastIfNeeded;
|
|
1044
|
+
private stopScreencastIfNeeded;
|
|
1045
|
+
bindClientToSession(clientId: string, sessionId: string): void;
|
|
1046
|
+
private sendBoundStatus;
|
|
1047
|
+
start(): Promise<void>;
|
|
1048
|
+
attachToServer(httpServer: Server, path?: string): Promise<void>;
|
|
1049
|
+
stop(): Promise<void>;
|
|
1050
|
+
private setupConnectionHandler;
|
|
1051
|
+
private handleInboundMessage;
|
|
1052
|
+
private handleClientDisconnect;
|
|
1053
|
+
private sendToClient;
|
|
1054
|
+
broadcastToSession(sessionId: string, message: WSMessage): void;
|
|
1055
|
+
broadcast(message: WSMessage): void;
|
|
1056
|
+
broadcastBinaryToSession(sessionId: string, payload: Buffer): void;
|
|
1057
|
+
getClientCount(): number;
|
|
1058
|
+
getSessionClientCount(sessionId: string): number;
|
|
1059
|
+
getRunning(): boolean;
|
|
1060
|
+
getPort(): number;
|
|
1073
1061
|
}
|
|
1074
1062
|
|
|
1075
1063
|
/**
|
|
@@ -1203,31 +1191,6 @@ declare function getWSServerFromCache(browserContext: XBContext): WSServer | und
|
|
|
1203
1191
|
*/
|
|
1204
1192
|
declare function setWSServerCache(browserContext: XBContext, server: WSServer): void;
|
|
1205
1193
|
|
|
1206
|
-
/**
|
|
1207
|
-
* Represents a managed browser session with its Playwright context, page,
|
|
1208
|
-
* and its own dedicated Browser connection.
|
|
1209
|
-
*/
|
|
1210
|
-
interface ManagedSession {
|
|
1211
|
-
id: string;
|
|
1212
|
-
name: string;
|
|
1213
|
-
context: XBContext;
|
|
1214
|
-
page: XBPage;
|
|
1215
|
-
browser: XBBrowser;
|
|
1216
|
-
createdAt: string;
|
|
1217
|
-
lastActivityAt: number;
|
|
1218
|
-
isCDP?: boolean;
|
|
1219
|
-
cdpEndpoint?: string;
|
|
1220
|
-
}
|
|
1221
|
-
/**
|
|
1222
|
-
* Options for launching or connecting to a browser instance.
|
|
1223
|
-
*/
|
|
1224
|
-
interface BrowserLaunchOptions {
|
|
1225
|
-
headless?: boolean;
|
|
1226
|
-
executablePath?: string;
|
|
1227
|
-
cdpEndpoint?: string;
|
|
1228
|
-
/** Enable CDP-level interception for anti-crawler protection */
|
|
1229
|
-
intercept?: boolean | CDPInterceptorConfig;
|
|
1230
|
-
}
|
|
1231
1194
|
/**
|
|
1232
1195
|
* Get or create the shared browser instance (lazy singleton).
|
|
1233
1196
|
*
|
|
@@ -1256,23 +1219,6 @@ declare function findSession(name: string): ManagedSession | undefined;
|
|
|
1256
1219
|
* @returns Array of all active sessions.
|
|
1257
1220
|
*/
|
|
1258
1221
|
declare function getAllSessions(): ManagedSession[];
|
|
1259
|
-
/**
|
|
1260
|
-
* Create a new browser session with a page and optional initial URL.
|
|
1261
|
-
*
|
|
1262
|
-
* Each session gets its own dedicated Browser connection. If connecting via
|
|
1263
|
-
* CDP, reuses existing pages when possible instead of creating a new
|
|
1264
|
-
* context/page pair.
|
|
1265
|
-
*
|
|
1266
|
-
* @param name - Unique name for the session.
|
|
1267
|
-
* @param url - Optional URL to navigate to after creation.
|
|
1268
|
-
* @param options - Browser launch or CDP connection options.
|
|
1269
|
-
* @returns The newly created managed session.
|
|
1270
|
-
*
|
|
1271
|
-
* @example
|
|
1272
|
-
* ```ts
|
|
1273
|
-
* const session = await createSession('default', 'https://example.com');
|
|
1274
|
-
* ```
|
|
1275
|
-
*/
|
|
1276
1222
|
declare function createSession(name: string, url?: string, options?: BrowserLaunchOptions): Promise<ManagedSession>;
|
|
1277
1223
|
/**
|
|
1278
1224
|
* Close a session by its name or ID.
|
|
@@ -1303,6 +1249,47 @@ declare function destroyBrowser(): Promise<void>;
|
|
|
1303
1249
|
*/
|
|
1304
1250
|
declare function resetForTesting(): void;
|
|
1305
1251
|
|
|
1252
|
+
declare function setWSServer(server: WSServer | null): void;
|
|
1253
|
+
|
|
1254
|
+
/**
|
|
1255
|
+
* Execute a single browser command against an existing session.
|
|
1256
|
+
*
|
|
1257
|
+
* Looks up the command by name, validates parameters via Zod schema,
|
|
1258
|
+
* resolves the target session, and runs the command handler.
|
|
1259
|
+
* Streams before/after events to the configured WebSocket server.
|
|
1260
|
+
*
|
|
1261
|
+
* @param commandName - Registered command name (e.g. "goto", "click", "fill").
|
|
1262
|
+
* @param params - Key-value parameters forwarded to the command handler.
|
|
1263
|
+
* @param sessionName - Name of the target session. Defaults to "default".
|
|
1264
|
+
* @returns An {@link ExecutionResult} with success status, data, and duration.
|
|
1265
|
+
*
|
|
1266
|
+
* @example
|
|
1267
|
+
* ```ts
|
|
1268
|
+
* const result = await executeCommand('click', { selector: '#submit' }, 'default');
|
|
1269
|
+
* if (result.success) console.log('Clicked!', result.data);
|
|
1270
|
+
* ```
|
|
1271
|
+
*/
|
|
1272
|
+
declare function executeCommand(commandName: string, params: Record<string, unknown>, sessionName?: string, extraOpts?: {
|
|
1273
|
+
cdpEndpoint?: string;
|
|
1274
|
+
skipCleanup?: boolean;
|
|
1275
|
+
timeout?: number;
|
|
1276
|
+
_recoveryAttempted?: boolean;
|
|
1277
|
+
}): Promise<ExecutionResult>;
|
|
1278
|
+
declare function executeChain(input: string, options?: {
|
|
1279
|
+
cdpEndpoint?: string;
|
|
1280
|
+
sessionName?: string;
|
|
1281
|
+
fileMode?: boolean;
|
|
1282
|
+
}): Promise<ChainExecutionResult>;
|
|
1283
|
+
/**
|
|
1284
|
+
* Check whether the given input string contains chain operators.
|
|
1285
|
+
*
|
|
1286
|
+
* Detects `&&`, `;`, `,`, `+`, and `->` surrounded by whitespace.
|
|
1287
|
+
*
|
|
1288
|
+
* @param input - The raw input string to test.
|
|
1289
|
+
* @returns `true` if chain operators are present.
|
|
1290
|
+
*/
|
|
1291
|
+
declare function isChainInput(input: string): boolean;
|
|
1292
|
+
|
|
1306
1293
|
/**
|
|
1307
1294
|
* Describes a single scope level in the browser automation hierarchy.
|
|
1308
1295
|
*/
|
|
@@ -2161,14 +2148,13 @@ declare class SessionRecorder {
|
|
|
2161
2148
|
private startUrl;
|
|
2162
2149
|
private startedAt;
|
|
2163
2150
|
private actions;
|
|
2164
|
-
private
|
|
2151
|
+
private networkCapture;
|
|
2165
2152
|
private contextChanges;
|
|
2166
2153
|
private checkpoints;
|
|
2167
2154
|
/** Proactive baseline scan of filter/sort/tab/menu regions. Keyed by
|
|
2168
2155
|
* containerSelector so re-scans after navigation replace rather than dup. */
|
|
2169
2156
|
private discoveredFilters;
|
|
2170
2157
|
private actionCounter;
|
|
2171
|
-
private networkCounter;
|
|
2172
2158
|
private contextCounter;
|
|
2173
2159
|
private checkpointCounter;
|
|
2174
2160
|
private pollTimer;
|
|
@@ -2176,19 +2162,11 @@ declare class SessionRecorder {
|
|
|
2176
2162
|
private lastActionTs;
|
|
2177
2163
|
private activePages;
|
|
2178
2164
|
private lastKnownUrl;
|
|
2179
|
-
/** Dedup map: key = normalizedType|tag|value → expiration timestamp.
|
|
2180
|
-
* Replaces old single-entry cdpActionDedup for bidirectional dedup. */
|
|
2181
2165
|
private dedupMap;
|
|
2182
2166
|
private dedupActionCount;
|
|
2183
|
-
/** Network dedup: last request key for short-window dedup */
|
|
2184
|
-
private _lastRequestKey;
|
|
2185
|
-
private _lastRequestTs;
|
|
2186
2167
|
private _isRecording;
|
|
2187
2168
|
private streamMode;
|
|
2188
|
-
/** Snapshot throttle: prevents too many screenshots during rapid inputs.
|
|
2189
|
-
* Keyed by 'type|elementSelector', value = last snapshot timestamp. */
|
|
2190
2169
|
private snapshotThrottle;
|
|
2191
|
-
/** Ambient action types: filtered out in clean mode */
|
|
2192
2170
|
private static readonly AMBIENT_TYPES;
|
|
2193
2171
|
constructor(context: XBContext, page: XBPage, sessionName: string);
|
|
2194
2172
|
get isRecording(): boolean;
|
|
@@ -2242,58 +2220,9 @@ declare class SessionRecorder {
|
|
|
2242
2220
|
private handleFileChooser;
|
|
2243
2221
|
private pollActions;
|
|
2244
2222
|
private flushPendingActions;
|
|
2245
|
-
/**
|
|
2246
|
-
* Capture a screenshot of the target element for key action types.
|
|
2247
|
-
* Returns a base64-encoded PNG string, or undefined if the element has no
|
|
2248
|
-
* selector or the screenshot fails (non-critical — never blocks recording).
|
|
2249
|
-
*
|
|
2250
|
-
* Only captures for: click, input, change, dblclick, and their CDP counterparts.
|
|
2251
|
-
*
|
|
2252
|
-
* Retry strategy (3 attempts, 3s each):
|
|
2253
|
-
* 1. element screenshot via locator
|
|
2254
|
-
* 2. retry element screenshot (element may have been animating/detached)
|
|
2255
|
-
* 3. fallback to viewport screenshot (so we always get *something*)
|
|
2256
|
-
*/
|
|
2257
|
-
private captureElementScreenshot;
|
|
2258
|
-
/**
|
|
2259
|
-
* Action types that trigger auto-snapshot capture.
|
|
2260
|
-
* Hover is excluded — it's too noisy and rarely changes the page visually.
|
|
2261
|
-
* Popup_appear captures the popup state (after only).
|
|
2262
|
-
*/
|
|
2263
|
-
private static readonly SNAPSHOT_TYPES;
|
|
2264
|
-
/**
|
|
2265
|
-
* Throttle key for snapshot capture to avoid too many during rapid inputs.
|
|
2266
|
-
* Returns true if this action should be throttled (skip snapshot).
|
|
2267
|
-
*/
|
|
2268
|
-
private isSnapshotThrottled;
|
|
2269
|
-
/**
|
|
2270
|
-
* Capture a viewport screenshot + compact accessibility tree for a key action.
|
|
2271
|
-
* - PNG stored in .tmp/snapshots/ (temporary, easy to clean up)
|
|
2272
|
-
* - aria tree stored inline as compact text on the action (searchable via grep)
|
|
2273
|
-
*
|
|
2274
|
-
* Non-blocking (errors silently caught). Throttled for rapid inputs.
|
|
2275
|
-
*/
|
|
2276
|
-
private captureAutoSnapshot;
|
|
2277
|
-
/**
|
|
2278
|
-
* After a click, wait 300ms then scan for popover/dropdown/menu elements
|
|
2279
|
-
* near the click position. This runs server-side to avoid race conditions
|
|
2280
|
-
* with the client-side poll interval.
|
|
2281
|
-
*/
|
|
2282
|
-
private captureClickContext;
|
|
2283
|
-
private detectCheckpoints;
|
|
2284
|
-
/**
|
|
2285
|
-
* After a key action (click/submit/input), check for success signals:
|
|
2286
|
-
* URL changes, recent successful network responses, dialog appearances.
|
|
2287
|
-
*/
|
|
2288
|
-
private verifyAction;
|
|
2289
2223
|
private flushToDisk;
|
|
2290
2224
|
private writeFinalOutput;
|
|
2291
2225
|
private buildData;
|
|
2292
|
-
private buildSummary;
|
|
2293
|
-
private matchActionToNetwork;
|
|
2294
|
-
private searchObjectForValue;
|
|
2295
|
-
private buildMarkdownSummary;
|
|
2296
|
-
static readMarkdownSummary(sessionName: string): string | null;
|
|
2297
2226
|
}
|
|
2298
2227
|
|
|
2299
2228
|
interface PlaybackOptions {
|
|
@@ -3026,47 +2955,6 @@ declare class HTTPServer {
|
|
|
3026
2955
|
} | null;
|
|
3027
2956
|
}
|
|
3028
2957
|
|
|
3029
|
-
/**
|
|
3030
|
-
* CDP Interceptor Proxy
|
|
3031
|
-
*
|
|
3032
|
-
* A thin WebSocket proxy that sits between any automation tool (Playwright,
|
|
3033
|
-
* Puppeteer, etc.) and Chromium's CDP endpoint. Every JSON-RPC message is
|
|
3034
|
-
* intercepted, analyzed against a rule engine, and either passed through,
|
|
3035
|
-
* blocked (with error response), or transformed before reaching the browser.
|
|
3036
|
-
*
|
|
3037
|
-
* Usage:
|
|
3038
|
-
* ```
|
|
3039
|
-
* const proxy = new CDPInterceptorProxy({ cdpEndpoint: 'ws://localhost:9222/...' });
|
|
3040
|
-
* await proxy.start(); // starts listening on a random port
|
|
3041
|
-
* // Now connect your automation tool to: ws://localhost:{proxy.port}
|
|
3042
|
-
* ```
|
|
3043
|
-
*/
|
|
3044
|
-
|
|
3045
|
-
declare class CDPInterceptorProxy {
|
|
3046
|
-
private wss;
|
|
3047
|
-
private engine;
|
|
3048
|
-
private config;
|
|
3049
|
-
private logger;
|
|
3050
|
-
private started;
|
|
3051
|
-
stats: CDPInterceptorStats;
|
|
3052
|
-
constructor(config: CDPInterceptorConfig);
|
|
3053
|
-
/** The port the proxy is listening on (only valid after start()) */
|
|
3054
|
-
get port(): number;
|
|
3055
|
-
/** Start the proxy server */
|
|
3056
|
-
start(): Promise<number>;
|
|
3057
|
-
/** Stop the proxy server */
|
|
3058
|
-
stop(): Promise<void>;
|
|
3059
|
-
/** Get accumulated statistics */
|
|
3060
|
-
getStats(): CDPInterceptorStats;
|
|
3061
|
-
/** Get recent log entries (for inspection) */
|
|
3062
|
-
getRecentLogs(count?: number): CDPLogEntry[];
|
|
3063
|
-
private handleConnection;
|
|
3064
|
-
private handleClientMessage;
|
|
3065
|
-
private handleBrowserMessage;
|
|
3066
|
-
private parseMessage;
|
|
3067
|
-
private recordDecision;
|
|
3068
|
-
}
|
|
3069
|
-
|
|
3070
2958
|
/**
|
|
3071
2959
|
* CDP Interceptor — Rule Engine
|
|
3072
2960
|
*
|