/** * Copyright (c) Microsoft Corporation. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import { createServer } from 'http'; export interface CDPRelayOptions { port?: number; host?: string; server?: ReturnType; } export interface CDPMessage { id?: number; method?: string; params?: any; sessionId?: string; result?: any; error?: { code: number; message: string; }; } export interface ConnectionInfo { type: 'connection_info'; sessionId: string; targetInfo?: any; } export declare class CDPRelay { private server; private wss; private port; private host; private ownsServer; private activeConnection; private playwrightSocket; private pendingMessages; private nextMessageId; constructor(options?: CDPRelayOptions); private setupWebSocketServer; /** * Handle Extension connection */ private _handleExtensionConnection; /** * Handle Playwright MCP connection */ private _handlePlaywrightConnection; private handleExtensionMessage; /** * Handle messages from Playwright MCP */ private _handlePlaywrightMessage; /** * Handle Browser domain methods locally */ private _handleBrowserDomainMethod; /** * Handle Target domain methods */ private _handleTargetDomainMethod; /** * Forward message to extension */ private _forwardToExtension; /** * Forward message to Playwright */ private _sendToPlaywright; /** * Send a CDP command to the connected browser tab */ sendCommand(method: string, params?: any, sessionId?: string): Promise; /** * Get the target info for the connected tab */ getTargetInfo(): any; /** * Check if there's an active connection */ isConnected(): boolean; /** * Get the session ID of the connected tab */ getSessionId(): string | undefined; /** * Update target info after navigation * This method fetches the current URL and title from the page * and updates the targetInfo object to keep it in sync with the actual page state */ updateTargetInfoAfterNavigation(): Promise; /** * Start the CDP relay server */ start(): Promise; /** * Stop the CDP relay server */ stop(): Promise; /** * Get the server URL for the extension */ getServerUrl(): string; /** * Get the CDP server URL for Playwright MCP */ getCdpUrl(): string; }