Skip to content
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

fix: explicit HTTPRequest.resourceType type defs #6882

Merged
merged 1 commit into from Feb 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 10 additions & 12 deletions src/common/HTTPRequest.ts
Expand Up @@ -45,6 +45,13 @@ export interface ResponseForRequest {
body: string | Buffer;
}

/**
* Resource types for HTTPRequests as perceived by the rendering engine.
*
* @public
*/
export type ResourceType = Lowercase<Protocol.Network.ResourceType>;

/**
*
* Represents an HTTP request sent by a page.
Expand Down Expand Up @@ -108,7 +115,7 @@ export class HTTPRequest {
private _allowInterception: boolean;
private _interceptionHandled = false;
private _url: string;
private _resourceType: string;
private _resourceType: ResourceType;

private _method: string;
private _postData?: string;
Expand All @@ -133,7 +140,7 @@ export class HTTPRequest {
this._interceptionId = interceptionId;
this._allowInterception = allowInterception;
this._url = event.request.url;
this._resourceType = event.type.toLowerCase();
this._resourceType = event.type.toLowerCase() as ResourceType;
this._method = event.request.method;
this._postData = event.request.postData;
this._frame = frame;
Expand All @@ -153,17 +160,8 @@ export class HTTPRequest {
/**
* Contains the request's resource type as it was perceived by the rendering
* engine.
* @remarks
* @returns one of the following: `document`, `stylesheet`, `image`, `media`,
* `font`, `script`, `texttrack`, `xhr`, `fetch`, `eventsource`, `websocket`,
* `manifest`, `other`.
*/
resourceType(): string {
// TODO (@jackfranklin): protocol.d.ts has a type for this, but all the
// string values are uppercase. The Puppeteer docs explicitly say the
// potential values are all lower case, and the constructor takes the event
// type and calls toLowerCase() on it, so we can't reuse the type from the
// protocol.d.ts. Why do we lower case?
resourceType(): ResourceType {
return this._resourceType;
}

Expand Down