From f0203864d17839ff6f27cf958c02bb8b3b87ed2c Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 22 May 2025 17:08:07 +0000 Subject: [PATCH] Update ConsoleMessage.type() to return specific string literals Co-authored-by: yury-s <9798949+yury-s@users.noreply.github.com> --- packages/playwright-client/types/types.d.ts | 139 ++++++++++---------- packages/playwright-core/types/types.d.ts | 139 ++++++++++---------- utils/generate_types/overrides.d.ts | 4 + 3 files changed, 142 insertions(+), 140 deletions(-) diff --git a/packages/playwright-client/types/types.d.ts b/packages/playwright-client/types/types.d.ts index cd23c6702f..f177d88318 100644 --- a/packages/playwright-client/types/types.d.ts +++ b/packages/playwright-client/types/types.d.ts @@ -16253,6 +16253,75 @@ export const _android: Android; export const _bidiChromium: BrowserType; export const _bidiFirefox: BrowserType; +/** + * [ConsoleMessage](https://playwright.dev/docs/api/class-consolemessage) objects are dispatched by page via the + * [page.on('console')](https://playwright.dev/docs/api/class-page#page-event-console) event. For each console message + * logged in the page there will be corresponding event in the Playwright context. + * + * ```js + * // Listen for all console logs + * page.on('console', msg => console.log(msg.text())); + * + * // Listen for all console events and handle errors + * page.on('console', msg => { + * if (msg.type() === 'error') + * console.log(`Error text: "${msg.text()}"`); + * }); + * + * // Get the next console log + * const msgPromise = page.waitForEvent('console'); + * await page.evaluate(() => { + * console.log('hello', 42, { foo: 'bar' }); // Issue console.log inside the page + * }); + * const msg = await msgPromise; + * + * // Deconstruct console log arguments + * await msg.args()[0].jsonValue(); // hello + * await msg.args()[1].jsonValue(); // 42 + * ``` + * + */ +export interface ConsoleMessage { + /** + * One of the following values: `'log'`, `'debug'`, `'info'`, `'error'`, `'warning'`, `'dir'`, `'dirxml'`, `'table'`, + * `'trace'`, `'clear'`, `'startGroup'`, `'startGroupCollapsed'`, `'endGroup'`, `'assert'`, `'profile'`, + * `'profileEnd'`, `'count'`, `'timeEnd'`. + */ + type(): 'log'|'debug'|'info'|'error'|'warning'|'dir'|'dirxml'|'table'|'trace'|'clear'|'startGroup'|'startGroupCollapsed'|'endGroup'|'assert'|'profile'|'profileEnd'|'count'|'timeEnd'; + /** + * List of arguments passed to a `console` function call. See also + * [page.on('console')](https://playwright.dev/docs/api/class-page#page-event-console). + */ + args(): Array; + + location(): { + /** + * URL of the resource. + */ + url: string; + + /** + * 0-based line number in the resource. + */ + lineNumber: number; + + /** + * 0-based column number in the resource. + */ + columnNumber: number; + }; + + /** + * The page that produced this console message, if any. + */ + page(): null|Page; + + /** + * The text of the console message. + */ + text(): string; +} + // This is required to not export everything by default. See https://github.com/Microsoft/TypeScript/issues/19545#issuecomment-340490459 export {}; @@ -18771,76 +18840,6 @@ export interface Clock { setSystemTime(time: number|string|Date): Promise; } -/** - * [ConsoleMessage](https://playwright.dev/docs/api/class-consolemessage) objects are dispatched by page via the - * [page.on('console')](https://playwright.dev/docs/api/class-page#page-event-console) event. For each console message - * logged in the page there will be corresponding event in the Playwright context. - * - * ```js - * // Listen for all console logs - * page.on('console', msg => console.log(msg.text())); - * - * // Listen for all console events and handle errors - * page.on('console', msg => { - * if (msg.type() === 'error') - * console.log(`Error text: "${msg.text()}"`); - * }); - * - * // Get the next console log - * const msgPromise = page.waitForEvent('console'); - * await page.evaluate(() => { - * console.log('hello', 42, { foo: 'bar' }); // Issue console.log inside the page - * }); - * const msg = await msgPromise; - * - * // Deconstruct console log arguments - * await msg.args()[0].jsonValue(); // hello - * await msg.args()[1].jsonValue(); // 42 - * ``` - * - */ -export interface ConsoleMessage { - /** - * List of arguments passed to a `console` function call. See also - * [page.on('console')](https://playwright.dev/docs/api/class-page#page-event-console). - */ - args(): Array; - - location(): { - /** - * URL of the resource. - */ - url: string; - - /** - * 0-based line number in the resource. - */ - lineNumber: number; - - /** - * 0-based column number in the resource. - */ - columnNumber: number; - }; - - /** - * The page that produced this console message, if any. - */ - page(): null|Page; - - /** - * The text of the console message. - */ - text(): string; - - /** - * One of the following values: `'log'`, `'debug'`, `'info'`, `'error'`, `'warning'`, `'dir'`, `'dirxml'`, `'table'`, - * `'trace'`, `'clear'`, `'startGroup'`, `'startGroupCollapsed'`, `'endGroup'`, `'assert'`, `'profile'`, - * `'profileEnd'`, `'count'`, `'timeEnd'`. - */ - type(): string; -} - /** * Coverage gathers information about parts of JavaScript and CSS that were used by the page. * diff --git a/packages/playwright-core/types/types.d.ts b/packages/playwright-core/types/types.d.ts index 2951f9ed9d..f177d88318 100644 --- a/packages/playwright-core/types/types.d.ts +++ b/packages/playwright-core/types/types.d.ts @@ -16253,6 +16253,75 @@ export const _android: Android; export const _bidiChromium: BrowserType; export const _bidiFirefox: BrowserType; +/** + * [ConsoleMessage](https://playwright.dev/docs/api/class-consolemessage) objects are dispatched by page via the + * [page.on('console')](https://playwright.dev/docs/api/class-page#page-event-console) event. For each console message + * logged in the page there will be corresponding event in the Playwright context. + * + * ```js + * // Listen for all console logs + * page.on('console', msg => console.log(msg.text())); + * + * // Listen for all console events and handle errors + * page.on('console', msg => { + * if (msg.type() === 'error') + * console.log(`Error text: "${msg.text()}"`); + * }); + * + * // Get the next console log + * const msgPromise = page.waitForEvent('console'); + * await page.evaluate(() => { + * console.log('hello', 42, { foo: 'bar' }); // Issue console.log inside the page + * }); + * const msg = await msgPromise; + * + * // Deconstruct console log arguments + * await msg.args()[0].jsonValue(); // hello + * await msg.args()[1].jsonValue(); // 42 + * ``` + * + */ +export interface ConsoleMessage { + /** + * One of the following values: `'log'`, `'debug'`, `'info'`, `'error'`, `'warning'`, `'dir'`, `'dirxml'`, `'table'`, + * `'trace'`, `'clear'`, `'startGroup'`, `'startGroupCollapsed'`, `'endGroup'`, `'assert'`, `'profile'`, + * `'profileEnd'`, `'count'`, `'timeEnd'`. + */ + type(): 'log'|'debug'|'info'|'error'|'warning'|'dir'|'dirxml'|'table'|'trace'|'clear'|'startGroup'|'startGroupCollapsed'|'endGroup'|'assert'|'profile'|'profileEnd'|'count'|'timeEnd'; + /** + * List of arguments passed to a `console` function call. See also + * [page.on('console')](https://playwright.dev/docs/api/class-page#page-event-console). + */ + args(): Array; + + location(): { + /** + * URL of the resource. + */ + url: string; + + /** + * 0-based line number in the resource. + */ + lineNumber: number; + + /** + * 0-based column number in the resource. + */ + columnNumber: number; + }; + + /** + * The page that produced this console message, if any. + */ + page(): null|Page; + + /** + * The text of the console message. + */ + text(): string; +} + // This is required to not export everything by default. See https://github.com/Microsoft/TypeScript/issues/19545#issuecomment-340490459 export {}; @@ -18771,76 +18840,6 @@ export interface Clock { setSystemTime(time: number|string|Date): Promise; } -/** - * [ConsoleMessage](https://playwright.dev/docs/api/class-consolemessage) objects are dispatched by page via the - * [page.on('console')](https://playwright.dev/docs/api/class-page#page-event-console) event. For each console message - * logged in the page there will be corresponding event in the Playwright context. - * - * ```js - * // Listen for all console logs - * page.on('console', msg => console.log(msg.text())); - * - * // Listen for all console events and handle errors - * page.on('console', msg => { - * if (msg.type() === 'error') - * console.log(`Error text: "${msg.text()}"`); - * }); - * - * // Get the next console log - * const msgPromise = page.waitForEvent('console'); - * await page.evaluate(() => { - * console.log('hello', 42, { foo: 'bar' }); // Issue console.log inside the page - * }); - * const msg = await msgPromise; - * - * // Deconstruct console log arguments - * await msg.args()[0].jsonValue(); // hello - * await msg.args()[1].jsonValue(); // 42 - * ``` - * - */ -export interface ConsoleMessage { - /** - * List of arguments passed to a `console` function call. See also - * [page.on('console')](https://playwright.dev/docs/api/class-page#page-event-console). - */ - args(): Array; - - location(): { - /** - * URL of the resource. - */ - url: string; - - /** - * 0-based line number in the resource. - */ - lineNumber: number; - - /** - * 0-based column number in the resource. - */ - columnNumber: number; - }; - - /** - * The page that produced this console message, if any. - */ - page(): null|Page; - - /** - * The text of the console message. - */ - text(): string; - - /** - * One of the following values: `'log'`, `'debug'`, `'info'`, `'error'`, `'warning'`, `'dir'`, `'dirxml'`, `'table'`, - * `'trace'`, `'clear'`, `'startGroup'`, `'startGroupCollapsed'`, `'endGroup'`, `'assert'`, `'profile'`, - * `'profileEnd'`, `'count'`, `'timeEnd'`. - */ - type(): 'log'|'debug'|'info'|'error'|'warning'|'dir'|'dirxml'|'table'|'trace'|'clear'|'startGroup'|'startGroupCollapsed'|'endGroup'|'assert'|'profile'|'profileEnd'|'count'|'timeEnd'; -} - /** * Coverage gathers information about parts of JavaScript and CSS that were used by the page. * diff --git a/utils/generate_types/overrides.d.ts b/utils/generate_types/overrides.d.ts index de8c95376b..cee7af1327 100644 --- a/utils/generate_types/overrides.d.ts +++ b/utils/generate_types/overrides.d.ts @@ -384,5 +384,9 @@ export const _android: Android; export const _bidiChromium: BrowserType; export const _bidiFirefox: BrowserType; +export interface ConsoleMessage { + type(): 'log'|'debug'|'info'|'error'|'warning'|'dir'|'dirxml'|'table'|'trace'|'clear'|'startGroup'|'startGroupCollapsed'|'endGroup'|'assert'|'profile'|'profileEnd'|'count'|'timeEnd'; +} + // This is required to not export everything by default. See https://github.com/Microsoft/TypeScript/issues/19545#issuecomment-340490459 export {};