chore: add client to HTTPRequest (#12267)

This commit is contained in:
Nikolay Vitkov 2024-04-12 14:39:04 +02:00 committed by GitHub
parent 402b4a4812
commit f00dca4129
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -31,7 +31,7 @@ export const requests = new WeakMap<Request, BidiHTTPRequest>();
export class BidiHTTPRequest extends HTTPRequest { export class BidiHTTPRequest extends HTTPRequest {
static from( static from(
bidiRequest: Request, bidiRequest: Request,
frame: BidiFrame | undefined, frame: BidiFrame,
redirect?: BidiHTTPRequest redirect?: BidiHTTPRequest
): BidiHTTPRequest { ): BidiHTTPRequest {
const request = new BidiHTTPRequest(bidiRequest, frame, redirect); const request = new BidiHTTPRequest(bidiRequest, frame, redirect);
@ -41,12 +41,12 @@ export class BidiHTTPRequest extends HTTPRequest {
#redirectBy: BidiHTTPRequest | undefined; #redirectBy: BidiHTTPRequest | undefined;
#response: BidiHTTPResponse | null = null; #response: BidiHTTPResponse | null = null;
override readonly id: string; override readonly id: string;
readonly #frame: BidiFrame | undefined; readonly #frame: BidiFrame;
readonly #request: Request; readonly #request: Request;
private constructor( private constructor(
request: Request, request: Request,
frame: BidiFrame | undefined, frame: BidiFrame,
redirectBy?: BidiHTTPRequest redirectBy?: BidiHTTPRequest
) { ) {
super(); super();
@ -61,7 +61,7 @@ export class BidiHTTPRequest extends HTTPRequest {
} }
override get client(): CDPSession { override get client(): CDPSession {
throw new UnsupportedOperation(); return this.#frame.client;
} }
#initialize() { #initialize() {
@ -74,7 +74,7 @@ export class BidiHTTPRequest extends HTTPRequest {
}); });
this.#request.on('authenticate', this.#handleAuthentication); this.#request.on('authenticate', this.#handleAuthentication);
this.#frame?.page().trustedEmitter.emit(PageEvent.Request, this); this.#frame.page().trustedEmitter.emit(PageEvent.Request, this);
} }
override url(): string { override url(): string {
@ -141,8 +141,8 @@ export class BidiHTTPRequest extends HTTPRequest {
return redirects; return redirects;
} }
override frame(): BidiFrame | null { override frame(): BidiFrame {
return this.#frame ?? null; return this.#frame;
} }
override async _continue( override async _continue(