Execute typed HTTP requests inside the browser context.
pageRequest()fetch() call inside the browser context via page.evaluate(). Because the request runs inside the real browser process, it uses the browser's TLS fingerprint, cookies, and session. It still looks like a fetch/XHR request, so use it for endpoints the site normally calls with fetch or XHR.pageRequest() is not a replacement for every browser request. For page HTML,
navigate with page.goto() or click a link. For images, scripts, stylesheets,
and iframes, let the DOM load the resource naturally when possible.12345async function pageRequest<T extends z.ZodType | undefined = undefined>( page: Page, config: RequestConfig, options?: PageRequestOptions<T>, ): Promise<T extends z.ZodType ? z.infer<T> : any>;
z.infer<T> when a schema is provided in options, or any otherwise.pageRequest to throw an error. The error message
includes the HTTP method, URL, and status code.RequestConfigpath urlstringrequiredpath method"GET" | "POST" | "PUT" | "DELETE" | "PATCH""GET".path headersRecord<string, string>bodyType adds
automatically.path bodyRecord<string, any> | stringbodyType is "json" (the default), objects are
serialized with JSON.stringify. When bodyType is "form", objects are
encoded as application/x-www-form-urlencoded.path bodyType"json" | "form"body. Defaults to "json". Setting this to "form"
also sets Content-Type: application/x-www-form-urlencoded automatically.path responseType"json" | "text" | "xml""json". Both "text" and "xml"
return the raw response text.PageRequestOptions<T>path loggerMinimalLoggerinfo level, and failures at warn.path schemaT extends z.ZodTypeschema.parse() before being returned. The return type of pageRequest becomes z.infer<T>.123456789101112131415161718import { pageRequest } from "libretto"; import { z } from "zod"; const ResultSchema = z.object({ items: z.array(z.object({ id: z.string(), name: z.string() })), total: z.number(), }); const data = await pageRequest( page, { url: "/api/search", method: "POST", body: { query: "example", page: 1 }, }, { schema: ResultSchema }, ); // data is typed as { items: Array<{ id: string; name: string }>; total: number }