-
Notifications
You must be signed in to change notification settings - Fork 68
fix: use own cdp implementation #1129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
8cc1b46
to
1223919
Compare
commit: |
9232a6d
to
56b81a4
Compare
"vite": "5.1.6", | ||
"wait-port": "1.1.0", | ||
"worker-farm": "1.7.0", | ||
"ws": "8.18.3", |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public readonly profiler: CDPProfiler; | ||
|
||
static async create(browser: Browser): Promise<CDP | null> { | ||
if (!browser.publicAPI.isChromium) { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
copied typings from https://chromedevtools.github.io/devtools-protocol/1-3/Profiler/
return new Promise(resolve => setTimeout(resolve, delay).unref()); | ||
}; | ||
|
||
export const extractRequestIdFromBrokenResponse = (message: string): number | null => { |
There was a problem hiding this comment.
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> { |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
retries "tryToSendRequest"
/** @description Closes websocket connection, terminating all pending requests */ | ||
close(): void { |
There was a problem hiding this comment.
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)
if (!this.isWebSocketActive(ws)) { | ||
clearInterval(pingInterval); | ||
return; | ||
} |
There was a problem hiding this comment.
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
fc679c0
to
0805224
Compare
0805224
to
0e0c4ed
Compare
0e0c4ed
to
641a566
Compare
No description provided.