diff --git a/packages/playwright-core/src/client/fetch.ts b/packages/playwright-core/src/client/fetch.ts index 58928532ac9e4..2cfbbff14bcf1 100644 --- a/packages/playwright-core/src/client/fetch.ts +++ b/packages/playwright-core/src/client/fetch.ts @@ -350,9 +350,9 @@ export class APIResponse implements api.APIResponse { return content.toString('utf8'); } - async json(): Promise { + async json(): Promise { const content = await this.text(); - return JSON.parse(content); + return JSON.parse(content) as T; } async [Symbol.asyncDispose]() { diff --git a/packages/playwright-core/src/client/network.ts b/packages/playwright-core/src/client/network.ts index cb18681ccf4e3..25007db199baf 100644 --- a/packages/playwright-core/src/client/network.ts +++ b/packages/playwright-core/src/client/network.ts @@ -718,9 +718,9 @@ export class Response extends ChannelOwner implements return content.toString('utf8'); } - async json(): Promise { + async json(): Promise { const content = await this.text(); - return JSON.parse(content); + return JSON.parse(content) as T; } request(): Request {