Skip to content

Conversation

KuznetsovRoman
Copy link
Member

No description provided.

@KuznetsovRoman KuznetsovRoman force-pushed the TESTPLANE-693.cdp branch 2 times, most recently from 8cc1b46 to 1223919 Compare September 5, 2025 20:53
Copy link

pkg-pr-new bot commented Sep 5, 2025

Open in StackBlitz

npm i https://pkg.pr.new/gemini-testing/testplane@1129

commit: 641a566

@KuznetsovRoman KuznetsovRoman force-pushed the TESTPLANE-693.cdp branch 4 times, most recently from 9232a6d to 56b81a4 Compare September 8, 2025 22:08
"vite": "5.1.6",
"wait-port": "1.1.0",
"worker-farm": "1.7.0",
"ws": "8.18.3",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

using this version because we already have it as "@testplane/[email protected]" dependency

import * as logger from "../../utils/logger";
import { EventEmitter } from "events";

export class CDPEventEmitter<Events extends { [key in keyof Events]: unknown }> extends EventEmitter {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This class provides typings for eventemitter, like that:
image
image

Also it wraps callbacks so they don't produce unhandled rejection

public readonly profiler: CDPProfiler;

static async create(browser: Browser): Promise<CDP | null> {
if (!browser.publicAPI.isChromium) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cdp is only available in chromium-based browsers

import { CDPEventEmitter } from "./emitter";
import type { CDPDebuggerLocation, CDPSessionId, CDPScriptCoverage, CDPProfile } from "./types";

interface StartPreciseCoverageRequest {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return new Promise(resolve => setTimeout(resolve, delay).unref());
};

export const extractRequestIdFromBrokenResponse = (message: string): number | null => {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as we have seen, we might get broken message, which can't be parsed with json.parse
This function extracts request "id", so we can stop waiting for response for it until timeout and just retry it

* @description creates ws connection with retries or returns existing one
* @note Concurrent requests with same params produce same ws connection
*/
private async getWsConnection(): Promise<WebSocket> {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Retries "tryToEstablishWsConnection"

}

/** @description establishes ws connection, sends request with timeout and waits for response */
private async tryToSendRequest(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes single try to send a request and resolves its response

}

/** @description Performs high-level CDP request with retries and timeouts */
async request<T>(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

retries "tryToSendRequest"

Comment on lines +481 to +482
/** @description Closes websocket connection, terminating all pending requests */
close(): void {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should only be called once, when we would not need this connection in the future (for example, when deleting browser session)

Comment on lines +531 to +534
if (!this.isWebSocketActive(ws)) {
clearInterval(pingInterval);
return;
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

on each tick we have to check it first, because we might catch a frame where this callback is called when this pingInterval is no longer active because ws connection is reestablished

@KuznetsovRoman KuznetsovRoman force-pushed the TESTPLANE-693.cdp branch 2 times, most recently from fc679c0 to 0805224 Compare September 9, 2025 15:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant