MCPcopy
hub / github.com/ChromeDevTools/chrome-devtools-mcp / getMockRequest

Function getMockRequest

tests/utils.ts:151–214  ·  view source on GitHub ↗
(
  options: {
    url?: string;
    method?: string;
    response?: HTTPResponse;
    failure?: HTTPRequest['failure'];
    resourceType?: string;
    hasPostData?: boolean;
    postData?: string;
    fetchPostData?: Promise<string>;
    stableId?: number;
    navigationRequest?: boolean;
    frame?: Frame;
    redirectChain?: HTTPRequest[];
    headers?: Record<string, string>;
  } = {},
)

Source from the content-addressed store, hash-verified

149}
150
151export function getMockRequest(
152 options: {
153 url?: string;
154 method?: string;
155 response?: HTTPResponse;
156 failure?: HTTPRequest['failure'];
157 resourceType?: string;
158 hasPostData?: boolean;
159 postData?: string;
160 fetchPostData?: Promise<string>;
161 stableId?: number;
162 navigationRequest?: boolean;
163 frame?: Frame;
164 redirectChain?: HTTPRequest[];
165 headers?: Record<string, string>;
166 } = {},
167): HTTPRequest {
168 return {
169 url() {
170 return options.url ?? 'http://example.com';
171 },
172 method() {
173 return options.method ?? 'GET';
174 },
175 fetchPostData() {
176 return options.fetchPostData ?? Promise.reject();
177 },
178 hasPostData() {
179 return options.hasPostData ?? false;
180 },
181 postData() {
182 return options.postData;
183 },
184 response() {
185 return options.response ?? null;
186 },
187 failure() {
188 return options.failure?.() ?? null;
189 },
190 resourceType() {
191 return options.resourceType ?? 'document';
192 },
193 headers(): Record<string, string> {
194 return (
195 options.headers ?? {
196 'content-size': '10',
197 }
198 );
199 },
200 redirectChain(): HTTPRequest[] {
201 // Puppeteer returns a fresh copy on every call (HTTPRequest returns
202 // `this._redirectChain.slice()`); mirror that so formatters can't share
203 // and accidentally mutate the same array across calls.
204 return [...(options.redirectChain ?? [])];
205 },
206 isNavigationRequest() {
207 return options.navigationRequest ?? false;
208 },

Callers 4

McpContext.test.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…