Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
TypeScript automationchromechromiume2e-testingelectronend-to-end-testingfirefoxjavascriptplaywrighttesttest-automationtestingtesting-toolswebwebkit
feat(fetch/network): add generic to json method (#34091)
Volodymyr Momot94ffbcb9c563
diff --git a/packages/playwright-core/src/client/fetch.ts b/packages/playwright-core/src/client/fetch.tsindex 58928532ac..2cfbbff14b 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<object> {+ async json<T = object>(): Promise<T> {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.tsindex cb18681ccf..25007db199 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<channels.ResponseChannel> implementsreturn content.toString('utf8');}- async json(): Promise<object> {+ async json<T = object>(): Promise<T> {const content = await this.text();- return JSON.parse(content);+ return JSON.parse(content) as T;}request(): Request {