Skip to content

Commit

Permalink
docs(consoleMessage): add missing console comments
Browse files Browse the repository at this point in the history
  • Loading branch information
kblok committed Apr 26, 2021
1 parent be27f47 commit 7ea4e4f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
21 changes: 21 additions & 0 deletions docs/src/api/class-consolemessage.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,25 @@
## method: ConsoleMessage.args
- returns: <[Array]<[JSHandle]>>

List or arguments passed to a `console` function call.

```js
const { chromium } = require('playwright'); // Or 'firefox' or 'webkit'.

(async () => {
const browser = await chromium.launch();
const page = await browser.newPage();
await Promise.all([
page.evaluate(() => console.log('hello', 5, {foo: 'bar'})),
page.waitForEvent('console')
]);
console.log(await message.args()[0].jsonValue()); // It will print 'hello'
console.log(await message.args()[1].jsonValue()); // It will print 5
console.log((await message.args()[2].jsonValue()).foo); // It will print 'bar'
await browser.close();
})();
```

## method: ConsoleMessage.location
* langs: js, python
- returns: <[Object]>
Expand All @@ -21,6 +40,8 @@ URL of the resource followed by 0-based line and column numbers in the resource
## method: ConsoleMessage.text
- returns: <[string]>

The text of the console message.

## method: ConsoleMessage.type
- returns: <[string]>

Expand Down
21 changes: 21 additions & 0 deletions types/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8978,6 +8978,24 @@ export interface BrowserServer {
* [page.on('console')](https://playwright.dev/docs/api/class-page#pageonconsole) event.
*/
export interface ConsoleMessage {
/**
* List or arguments passed to a `console` function call.
*
* ```js
* const { chromium } = require('playwright'); // Or 'firefox' or 'webkit'.
*
* (async () => {
* const browser = await chromium.launch();
* const page = await browser.newPage();
* page.evaluate(() => console.log('hello', 5, {foo: 'bar'})),
* console.log(await message.args()[0].jsonValue()); // It will print 'hello'
* console.log(await message.args()[1].jsonValue()); // It will print 5
* console.log((await message.args()[2].jsonValue()).foo); // It will print 'bar'
* await browser.close();
* })();
* ```
*
*/
args(): Array<JSHandle>;

location(): {
Expand All @@ -8997,6 +9015,9 @@ export interface ConsoleMessage {
columnNumber: number;
};

/**
* The text of the console message.
*/
text(): string;

/**
Expand Down

0 comments on commit 7ea4e4f

Please sign in to comment.