puppeteer-core
Version:
A high-level API to control headless Chrome over the DevTools Protocol
180 lines (146 loc) • 4.42 kB
text/typescript
/**
* @license
* Copyright 2020 Google Inc.
* SPDX-License-Identifier: Apache-2.0
*/
import type * as Bidi from 'chromium-bidi/lib/cjs/protocol/protocol.js';
import type {CDPSession} from '../api/CDPSession.js';
import type {
ContinueRequestOverrides,
ResponseForRequest,
} from '../api/HTTPRequest.js';
import {HTTPRequest, type ResourceType} from '../api/HTTPRequest.js';
import {PageEvent} from '../api/Page.js';
import {UnsupportedOperation} from '../common/Errors.js';
import type {Request} from './core/Request.js';
import type {BidiFrame} from './Frame.js';
import {BidiHTTPResponse} from './HTTPResponse.js';
export const requests = new WeakMap<Request, BidiHTTPRequest>();
/**
* @internal
*/
export class BidiHTTPRequest extends HTTPRequest {
static from(
bidiRequest: Request,
frame: BidiFrame | undefined
): BidiHTTPRequest {
const request = new BidiHTTPRequest(bidiRequest, frame);
request.
return request;
}
override readonly id: string;
readonly
readonly
private constructor(request: Request, frame: BidiFrame | undefined) {
super();
requests.set(request, this);
this.
this.
this.id = request.id;
}
override get client(): CDPSession {
throw new UnsupportedOperation();
}
this.
this.
});
this.
this.
});
this.
}
override url(): string {
return this.
}
override resourceType(): ResourceType {
return this.initiator().type.toLowerCase() as ResourceType;
}
override method(): string {
return this.
}
override postData(): string | undefined {
throw new UnsupportedOperation();
}
override hasPostData(): boolean {
throw new UnsupportedOperation();
}
override async fetchPostData(): Promise<string | undefined> {
throw new UnsupportedOperation();
}
override headers(): Record<string, string> {
const headers: Record<string, string> = {};
for (const header of this.
headers[header.name.toLowerCase()] = header.value.value;
}
return headers;
}
override response(): BidiHTTPResponse | null {
return this.
}
override failure(): {errorText: string} | null {
if (this.
return null;
}
return {errorText: this.
}
override isNavigationRequest(): boolean {
return this.
}
override initiator(): Bidi.Network.Initiator {
return this.
}
override redirectChain(): BidiHTTPRequest[] {
if (this.
return [];
}
const redirects = [this.
for (const redirect of redirects) {
if (redirect.
redirects.push(redirect.
}
}
return redirects;
}
override enqueueInterceptAction(
pendingHandler: () => void | PromiseLike<unknown>
): void {
// Execute the handler when interception is not supported
void pendingHandler();
}
override frame(): BidiFrame | null {
return this.
}
override continueRequestOverrides(): never {
throw new UnsupportedOperation();
}
override continue(_overrides: ContinueRequestOverrides = {}): never {
throw new UnsupportedOperation();
}
override responseForRequest(): never {
throw new UnsupportedOperation();
}
override abortErrorReason(): never {
throw new UnsupportedOperation();
}
override interceptResolutionState(): never {
throw new UnsupportedOperation();
}
override isInterceptResolutionHandled(): never {
throw new UnsupportedOperation();
}
override finalizeInterceptions(): never {
throw new UnsupportedOperation();
}
override abort(): never {
throw new UnsupportedOperation();
}
override respond(
_response: Partial<ResponseForRequest>,
_priority?: number
): never {
throw new UnsupportedOperation();
}
}