tsc
This commit is contained in:
@@ -22,6 +22,8 @@
|
||||
* - /extension/guid - Extension connection for chrome.debugger forwarding
|
||||
*/
|
||||
|
||||
import net from 'net'
|
||||
|
||||
import { spawn } from 'child_process';
|
||||
import http from 'http';
|
||||
|
||||
@@ -29,14 +31,13 @@ import { debug, ws, wsServer } from 'playwright-core/lib/utilsBundle';
|
||||
import { registry } from 'playwright-core/lib/server/registry/index';
|
||||
import { ManualPromise } from 'playwright-core/lib/utils';
|
||||
|
||||
import { httpAddressToString } from '../sdk/http.js';
|
||||
import { logUnhandledError } from '../log.js';
|
||||
|
||||
import * as protocol from './protocol.js';
|
||||
|
||||
import type websocket from 'ws';
|
||||
import type { ClientInfo } from '../sdk/server.js';
|
||||
import type { ExtensionCommand, ExtensionEvents } from './protocol.js';
|
||||
import type { WebSocket, WebSocketServer } from 'playwright-core/lib/utilsBundle';
|
||||
import { ClientInfo } from './types.js';
|
||||
|
||||
|
||||
const debugLogger = debug('pw:mcp:relay');
|
||||
@@ -219,6 +220,7 @@ export class CDPRelayServer {
|
||||
void this._extensionConnectionPromise.catch(logUnhandledError);
|
||||
}
|
||||
|
||||
|
||||
private _closePlaywrightConnection(reason: string) {
|
||||
if (this._playwrightConnection?.readyState === ws.OPEN)
|
||||
this._playwrightConnection.close(1000, reason);
|
||||
@@ -422,3 +424,20 @@ class ExtensionConnection {
|
||||
this._callbacks.clear();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export function httpAddressToString(address: string | net.AddressInfo | null): string {
|
||||
|
||||
if (!address)
|
||||
throw new Error('Invalid null address passeds to httpAddressToString');
|
||||
if (typeof address === 'string')
|
||||
return address;
|
||||
const resolvedPort = address.port;
|
||||
let resolvedHost = address.family === 'IPv4' ? address.address : `[${address.address}]`;
|
||||
if (resolvedHost === '0.0.0.0' || resolvedHost === '[::]')
|
||||
resolvedHost = 'localhost';
|
||||
return `http://${resolvedHost}:${resolvedPort}`;
|
||||
}
|
||||
function logUnhandledError(e: unknown) {
|
||||
debugLogger('Unhandled promise rejection:', e instanceof Error ? e.stack || e.message : e);
|
||||
}
|
||||
|
||||
@@ -21,9 +21,9 @@ import http from 'http';
|
||||
import net from 'net'
|
||||
|
||||
import { CDPRelayServer } from './cdpRelay.js';
|
||||
import { BrowserContextFactory, ClientInfo } from './types.js';
|
||||
|
||||
|
||||
import type { BrowserContextFactory } from '../browser/browserContextFactory.js';
|
||||
import type { ClientInfo } from '../sdk/server';
|
||||
|
||||
const debugLogger = debug('pw:mcp:relay');
|
||||
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
import * as playwright from 'playwright-core';
|
||||
|
||||
|
||||
export type BrowserContextFactoryResult = {
|
||||
browserContext: playwright.BrowserContext;
|
||||
close: (afterClose: () => Promise<void>) => Promise<void>;
|
||||
};
|
||||
|
||||
export interface BrowserContextFactory {
|
||||
createContext(clientInfo: ClientInfo, abortSignal: AbortSignal, toolName: string | undefined): Promise<BrowserContextFactoryResult>;
|
||||
}
|
||||
|
||||
export type ClientInfo = {
|
||||
name: string;
|
||||
version: string;
|
||||
roots: Root[];
|
||||
timestamp: number;
|
||||
};
|
||||
|
||||
type Root = never // something mcp
|
||||
Reference in New Issue
Block a user