This commit is contained in:
nik
2025-10-03 22:27:28 +03:00
parent 829fad0e17
commit 871cf7e792
16520 changed files with 2967597 additions and 3 deletions

54
node_modules/chromium-bidi/lib/cjs/cdp/CdpClient.d.ts generated vendored Normal file
View File

@@ -0,0 +1,54 @@
/**
* Copyright 2021 Google LLC.
* 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 type { Protocol } from 'devtools-protocol';
import type { ProtocolMapping } from 'devtools-protocol/types/protocol-mapping.js';
import { EventEmitter } from '../utils/EventEmitter.js';
import type { MapperCdpConnection } from './CdpConnection.js';
export type CdpEvents = {
[Property in keyof ProtocolMapping.Events]: ProtocolMapping.Events[Property][0];
};
/** An error that will be thrown if/when the connection is closed. */
export declare class CloseError extends Error {
}
export interface CdpClient extends EventEmitter<CdpEvents> {
/** Unique session identifier. */
sessionId: Protocol.Target.SessionID | undefined;
/**
* Provides an unique way to detect if an error was caused by the closure of a
* Target or Session.
*
* @example During the creation of a subframe we navigate the main frame.
* The subframe Target is closed while initialized commands are in-flight.
* In this case we want to swallow the thrown error.
*/
isCloseError(error: unknown): boolean;
/**
* Returns a command promise, which will be resolved with the command result
* after receiving the result from CDP.
* @param method Name of the CDP command to call.
* @param params Parameters to pass to the CDP command.
*/
sendCommand<CdpMethod extends keyof ProtocolMapping.Commands>(method: CdpMethod, params?: ProtocolMapping.Commands[CdpMethod]['paramsType'][0]): Promise<ProtocolMapping.Commands[CdpMethod]['returnType']>;
}
/** Represents a high-level CDP connection to the browser. */
export declare class MapperCdpClient extends EventEmitter<CdpEvents> implements CdpClient {
#private;
constructor(cdpConnection: MapperCdpConnection, sessionId?: Protocol.Target.SessionID);
get sessionId(): Protocol.Target.SessionID | undefined;
sendCommand<CdpMethod extends keyof ProtocolMapping.Commands>(method: CdpMethod, ...params: ProtocolMapping.Commands[CdpMethod]['paramsType']): Promise<ProtocolMapping.Commands[CdpMethod]['returnType']>;
isCloseError(error: unknown): boolean;
}

45
node_modules/chromium-bidi/lib/cjs/cdp/CdpClient.js generated vendored Normal file
View File

@@ -0,0 +1,45 @@
"use strict";
/**
* Copyright 2021 Google LLC.
* 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.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.MapperCdpClient = exports.CloseError = void 0;
const EventEmitter_js_1 = require("../utils/EventEmitter.js");
/** An error that will be thrown if/when the connection is closed. */
class CloseError extends Error {
}
exports.CloseError = CloseError;
/** Represents a high-level CDP connection to the browser. */
class MapperCdpClient extends EventEmitter_js_1.EventEmitter {
#cdpConnection;
#sessionId;
constructor(cdpConnection, sessionId) {
super();
this.#cdpConnection = cdpConnection;
this.#sessionId = sessionId;
}
get sessionId() {
return this.#sessionId;
}
sendCommand(method, ...params) {
return this.#cdpConnection.sendCommand(method, params[0], this.#sessionId);
}
isCloseError(error) {
return error instanceof CloseError;
}
}
exports.MapperCdpClient = MapperCdpClient;
//# sourceMappingURL=CdpClient.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"CdpClient.js","sourceRoot":"","sources":["../../../src/cdp/CdpClient.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;AAKH,8DAAsD;AAQtD,qEAAqE;AACrE,MAAa,UAAW,SAAQ,KAAK;CAAG;AAAxC,gCAAwC;AA4BxC,6DAA6D;AAC7D,MAAa,eACX,SAAQ,8BAAuB;IAG/B,cAAc,CAAsB;IACpC,UAAU,CAA6B;IAEvC,YACE,aAAkC,EAClC,SAAqC;QAErC,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,cAAc,GAAG,aAAa,CAAC;QACpC,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;IAC9B,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,UAAU,CAAC;IACzB,CAAC;IAED,WAAW,CACT,MAAiB,EACjB,GAAG,MAAyD;QAE5D,OAAO,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC;IAC7E,CAAC;IAED,YAAY,CAAC,KAAc;QACzB,OAAO,KAAK,YAAY,UAAU,CAAC;IACrC,CAAC;CACF;AA9BD,0CA8BC"}

View File

@@ -0,0 +1,45 @@
/**
* Copyright 2021 Google LLC.
* 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 type { Protocol } from 'devtools-protocol';
import type { ProtocolMapping } from 'devtools-protocol/types/protocol-mapping.js';
import type { LoggerFn } from '../utils/log.js';
import type { Transport } from '../utils/transport.js';
import { MapperCdpClient, type CdpClient } from './CdpClient.js';
export interface CdpConnection {
getCdpClient(sessionId: Protocol.Target.SessionID): CdpClient;
}
/**
* Represents a high-level CDP connection to the browser backend.
*
* Manages all CdpClients (each backed by a Session ID) instance for each active
* CDP session.
*/
export declare class MapperCdpConnection implements CdpConnection {
#private;
static readonly LOGGER_PREFIX_RECV: "cdp:RECV ◂";
static readonly LOGGER_PREFIX_SEND: "cdp:SEND ▸";
constructor(transport: Transport, logger?: LoggerFn);
/** Closes the connection to the browser. */
close(): void;
createBrowserSession(): Promise<MapperCdpClient>;
/**
* Gets a CdpClient instance attached to the given session ID,
* or null if the session is not attached.
*/
getCdpClient(sessionId: Protocol.Target.SessionID): MapperCdpClient;
sendCommand<CdpMethod extends keyof ProtocolMapping.Commands>(method: CdpMethod, params?: ProtocolMapping.Commands[CdpMethod]['paramsType'][0], sessionId?: Protocol.Target.SessionID): Promise<object>;
}

134
node_modules/chromium-bidi/lib/cjs/cdp/CdpConnection.js generated vendored Normal file
View File

@@ -0,0 +1,134 @@
"use strict";
var _a;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MapperCdpConnection = void 0;
const log_js_1 = require("../utils/log.js");
const CdpClient_js_1 = require("./CdpClient.js");
/**
* Represents a high-level CDP connection to the browser backend.
*
* Manages all CdpClients (each backed by a Session ID) instance for each active
* CDP session.
*/
class MapperCdpConnection {
static LOGGER_PREFIX_RECV = `${log_js_1.LogType.cdp}:RECV ◂`;
static LOGGER_PREFIX_SEND = `${log_js_1.LogType.cdp}:SEND ▸`;
#mainBrowserCdpClient;
#transport;
/** Map from session ID to CdpClient.
* `undefined` points to the main browser session. */
#sessionCdpClients = new Map();
#commandCallbacks = new Map();
#logger;
#nextId = 0;
constructor(transport, logger) {
this.#transport = transport;
this.#logger = logger;
this.#transport.setOnMessage(this.#onMessage);
// Create default Browser CDP Session.
this.#mainBrowserCdpClient = this.#createCdpClient(undefined);
}
/** Closes the connection to the browser. */
close() {
this.#transport.close();
for (const [, { reject, error }] of this.#commandCallbacks) {
reject(error);
}
this.#commandCallbacks.clear();
this.#sessionCdpClients.clear();
}
async createBrowserSession() {
const { sessionId } = await this.#mainBrowserCdpClient.sendCommand('Target.attachToBrowserTarget');
return this.#createCdpClient(sessionId);
}
/**
* Gets a CdpClient instance attached to the given session ID,
* or null if the session is not attached.
*/
getCdpClient(sessionId) {
const cdpClient = this.#sessionCdpClients.get(sessionId);
if (!cdpClient) {
throw new Error(`Unknown CDP session ID: ${sessionId}`);
}
return cdpClient;
}
sendCommand(method, params, sessionId) {
return new Promise((resolve, reject) => {
const id = this.#nextId++;
this.#commandCallbacks.set(id, {
sessionId,
resolve,
reject,
error: new CdpClient_js_1.CloseError(`${method} ${JSON.stringify(params)} ${sessionId ?? ''} call rejected because the connection has been closed.`),
});
const cdpMessage = { id, method, params };
if (sessionId) {
cdpMessage.sessionId = sessionId;
}
void this.#transport
.sendMessage(JSON.stringify(cdpMessage))
?.catch((error) => {
this.#logger?.(log_js_1.LogType.debugError, error);
this.#transport.close();
});
this.#logger?.(_a.LOGGER_PREFIX_SEND, cdpMessage);
});
}
#onMessage = (json) => {
const message = JSON.parse(json);
this.#logger?.(_a.LOGGER_PREFIX_RECV, message);
// Update client map if a session is attached
// Listen for these events on every session.
if (message.method === 'Target.attachedToTarget') {
const { sessionId } = message.params;
this.#createCdpClient(sessionId);
}
if (message.id !== undefined) {
// Handle command response.
const callbacks = this.#commandCallbacks.get(message.id);
this.#commandCallbacks.delete(message.id);
if (callbacks) {
if (message.result) {
callbacks.resolve(message.result);
}
else if (message.error) {
callbacks.reject(message.error);
}
}
}
else if (message.method) {
const client = this.#sessionCdpClients.get(message.sessionId ?? undefined);
client?.emit(message.method, message.params || {});
// Update client map if a session is detached
// But emit on that session
if (message.method === 'Target.detachedFromTarget') {
const { sessionId } = message.params;
const client = this.#sessionCdpClients.get(sessionId);
if (client) {
this.#sessionCdpClients.delete(sessionId);
client.removeAllListeners();
}
// Reject all the pending commands for the detached session.
for (const callback of this.#commandCallbacks.values()) {
if (callback.sessionId === sessionId) {
callback.reject(callback.error);
}
}
}
}
};
/**
* Creates a new CdpClient instance for the given session ID.
* @param sessionId either a string, or undefined for the main browser session.
* The main browser session is used only to create new browser sessions.
* @private
*/
#createCdpClient(sessionId) {
const cdpClient = new CdpClient_js_1.MapperCdpClient(this, sessionId);
this.#sessionCdpClients.set(sessionId, cdpClient);
return cdpClient;
}
}
exports.MapperCdpConnection = MapperCdpConnection;
_a = MapperCdpConnection;
//# sourceMappingURL=CdpConnection.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"CdpConnection.js","sourceRoot":"","sources":["../../../src/cdp/CdpConnection.ts"],"names":[],"mappings":";;;;AAmBA,4CAAwC;AAIxC,iDAA2E;AAc3E;;;;;GAKG;AACH,MAAa,mBAAmB;IAC9B,MAAM,CAAU,kBAAkB,GAAG,GAAG,gBAAO,CAAC,GAAG,SAAkB,CAAC;IACtE,MAAM,CAAU,kBAAkB,GAAG,GAAG,gBAAO,CAAC,GAAG,SAAkB,CAAC;IAE7D,qBAAqB,CAAkB;IACvC,UAAU,CAAY;IAE/B;yDACqD;IAC5C,kBAAkB,GAAG,IAAI,GAAG,EAGlC,CAAC;IACK,iBAAiB,GAAG,IAAI,GAAG,EAAwB,CAAC;IACpD,OAAO,CAAY;IAC5B,OAAO,GAAG,CAAC,CAAC;IAEZ,YAAY,SAAoB,EAAE,MAAiB;QACjD,IAAI,CAAC,UAAU,GAAG,SAAS,CAAC;QAC5B,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,UAAU,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;QAE9C,sCAAsC;QACtC,IAAI,CAAC,qBAAqB,GAAG,IAAI,CAAC,gBAAgB,CAAC,SAAS,CAAC,CAAC;IAChE,CAAC;IAED,4CAA4C;IAC5C,KAAK;QACH,IAAI,CAAC,UAAU,CAAC,KAAK,EAAE,CAAC;QACxB,KAAK,MAAM,CAAC,EAAE,EAAC,MAAM,EAAE,KAAK,EAAC,CAAC,IAAI,IAAI,CAAC,iBAAiB,EAAE,CAAC;YACzD,MAAM,CAAC,KAAK,CAAC,CAAC;QAChB,CAAC;QACD,IAAI,CAAC,iBAAiB,CAAC,KAAK,EAAE,CAAC;QAC/B,IAAI,CAAC,kBAAkB,CAAC,KAAK,EAAE,CAAC;IAClC,C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CAAC,GAAG,CACxC,OAAO,CAAC,SAAS,IAAI,SAAS,CAC/B,CAAC;YACF,MAAM,EAAE,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;YAEnD,6CAA6C;YAC7C,2BAA2B;YAC3B,IAAI,OAAO,CAAC,MAAM,KAAK,2BAA2B,EAAE,CAAC;gBACnD,MAAM,EAAC,SAAS,EAAC,GAAG,OAAO,CAAC,MAAM,CAAC;gBACnC,MAAM,MAAM,GAAG,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;gBACtD,IAAI,MAAM,EAAE,CAAC;oBACX,IAAI,CAAC,kBAAkB,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;oBAC1C,MAAM,CAAC,kBAAkB,EAAE,CAAC;gBAC9B,CAAC;gBACD,4DAA4D;gBAC5D,KAAK,MAAM,QAAQ,IAAI,IAAI,CAAC,iBAAiB,CAAC,MAAM,EAAE,EAAE,CAAC;oBACvD,IAAI,QAAQ,CAAC,SAAS,KAAK,SAAS,EAAE,CAAC;wBACrC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;oBAClC,CAAC;gBACH,CAAC;YACH,CAAC;QACH,CAAC;IACH,CAAC,CAAC;IAEF;;;;;OAKG;IACH,gBAAgB,CACd,SAAgD;QAEhD,MAAM,SAAS,GAAG,IAAI,8BAAe,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QACvD,IAAI,CAAC,kBAAkB,CAAC,GAAG,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QAClD,OAAO,SAAS,CAAC;IACnB,CAAC;;AAlJH,kDAmJC"}

30
node_modules/chromium-bidi/lib/cjs/cdp/cdpMessage.d.ts generated vendored Normal file
View File

@@ -0,0 +1,30 @@
/**
* Copyright 2021 Google LLC.
* 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 type { Protocol } from 'devtools-protocol';
import type { ProtocolMapping } from 'devtools-protocol/types/protocol-mapping.js';
export interface CdpError {
code: number;
message: string;
}
export interface CdpMessage<CdpMethod extends keyof ProtocolMapping.Commands> {
sessionId?: Protocol.Target.SessionID;
id?: number;
error?: CdpError;
method?: CdpMethod;
params?: ProtocolMapping.Commands[CdpMethod]['paramsType'][0];
result?: ProtocolMapping.Commands[CdpMethod]['returnType'];
}

3
node_modules/chromium-bidi/lib/cjs/cdp/cdpMessage.js generated vendored Normal file
View File

@@ -0,0 +1,3 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
//# sourceMappingURL=cdpMessage.js.map

View File

@@ -0,0 +1 @@
{"version":3,"file":"cdpMessage.js","sourceRoot":"","sources":["../../../src/cdp/cdpMessage.ts"],"names":[],"mappings":""}