diff --git a/new-docs/puppeteer.consolemessage._constructor_.md b/new-docs/puppeteer.consolemessage._constructor_.md
index 16ab061463dbd..79ca5dfa3eb10 100644
--- a/new-docs/puppeteer.consolemessage._constructor_.md
+++ b/new-docs/puppeteer.consolemessage._constructor_.md
@@ -9,15 +9,15 @@ Constructs a new instance of the `ConsoleMessage` class
Signature:
```typescript
-constructor(type: string, text: string, args: JSHandle[], location?: ConsoleMessageLocation);
+constructor(type: ConsoleMessageType, text: string, args: JSHandle[], location?: ConsoleMessageLocation);
```
## Parameters
| Parameter | Type | Description |
| --- | --- | --- |
-| type | string | |
+| type | [ConsoleMessageType](./puppeteer.consolemessagetype.md) | |
| text | string | |
| args | [JSHandle](./puppeteer.jshandle.md)\[\] | |
-| location | ConsoleMessageLocation | |
+| location | [ConsoleMessageLocation](./puppeteer.consolemessagelocation.md) | |
diff --git a/new-docs/puppeteer.consolemessage.args.md b/new-docs/puppeteer.consolemessage.args.md
index d0a4810276cc8..6ba2fdb469b8b 100644
--- a/new-docs/puppeteer.consolemessage.args.md
+++ b/new-docs/puppeteer.consolemessage.args.md
@@ -13,3 +13,5 @@ args(): JSHandle[];
[JSHandle](./puppeteer.jshandle.md)\[\]
+An array of arguments passed to the console.
+
diff --git a/new-docs/puppeteer.consolemessage.location.md b/new-docs/puppeteer.consolemessage.location.md
index e8df630ba4e9f..f9b2f799fd857 100644
--- a/new-docs/puppeteer.consolemessage.location.md
+++ b/new-docs/puppeteer.consolemessage.location.md
@@ -11,5 +11,7 @@ location(): ConsoleMessageLocation;
```
Returns:
-ConsoleMessageLocation
+[ConsoleMessageLocation](./puppeteer.consolemessagelocation.md)
+
+The location of the console message.
diff --git a/new-docs/puppeteer.consolemessage.md b/new-docs/puppeteer.consolemessage.md
index d26285c22fe25..0b3f84a047a3b 100644
--- a/new-docs/puppeteer.consolemessage.md
+++ b/new-docs/puppeteer.consolemessage.md
@@ -4,6 +4,8 @@
## ConsoleMessage class
+ConsoleMessage objects are dispatched by page via the 'console' event.
+
Signature:
```typescript
diff --git a/new-docs/puppeteer.consolemessage.text.md b/new-docs/puppeteer.consolemessage.text.md
index 5a687bb4b62c2..38634ba8e5d51 100644
--- a/new-docs/puppeteer.consolemessage.text.md
+++ b/new-docs/puppeteer.consolemessage.text.md
@@ -13,3 +13,5 @@ text(): string;
string
+The text of the console message.
+
diff --git a/new-docs/puppeteer.consolemessage.type.md b/new-docs/puppeteer.consolemessage.type.md
index 69f6259ad579a..4b0e14fa06ae6 100644
--- a/new-docs/puppeteer.consolemessage.type.md
+++ b/new-docs/puppeteer.consolemessage.type.md
@@ -7,9 +7,11 @@
Signature:
```typescript
-type(): string;
+type(): ConsoleMessageType;
```
Returns:
-string
+[ConsoleMessageType](./puppeteer.consolemessagetype.md)
+
+The type of the console message.
diff --git a/new-docs/puppeteer.consolemessagelocation.columnnumber.md b/new-docs/puppeteer.consolemessagelocation.columnnumber.md
new file mode 100644
index 0000000000000..42ff62c08ebf2
--- /dev/null
+++ b/new-docs/puppeteer.consolemessagelocation.columnnumber.md
@@ -0,0 +1,13 @@
+
+
+[Home](./index.md) > [puppeteer](./puppeteer.md) > [ConsoleMessageLocation](./puppeteer.consolemessagelocation.md) > [columnNumber](./puppeteer.consolemessagelocation.columnnumber.md)
+
+## ConsoleMessageLocation.columnNumber property
+
+0-based column number in the resource if known or `undefined` otherwise.
+
+Signature:
+
+```typescript
+columnNumber?: number;
+```
diff --git a/new-docs/puppeteer.consolemessagelocation.linenumber.md b/new-docs/puppeteer.consolemessagelocation.linenumber.md
new file mode 100644
index 0000000000000..9ddd1fce4015b
--- /dev/null
+++ b/new-docs/puppeteer.consolemessagelocation.linenumber.md
@@ -0,0 +1,13 @@
+
+
+[Home](./index.md) > [puppeteer](./puppeteer.md) > [ConsoleMessageLocation](./puppeteer.consolemessagelocation.md) > [lineNumber](./puppeteer.consolemessagelocation.linenumber.md)
+
+## ConsoleMessageLocation.lineNumber property
+
+0-based line number in the resource if known or `undefined` otherwise.
+
+Signature:
+
+```typescript
+lineNumber?: number;
+```
diff --git a/new-docs/puppeteer.consolemessagelocation.md b/new-docs/puppeteer.consolemessagelocation.md
new file mode 100644
index 0000000000000..854c090d0390b
--- /dev/null
+++ b/new-docs/puppeteer.consolemessagelocation.md
@@ -0,0 +1,21 @@
+
+
+[Home](./index.md) > [puppeteer](./puppeteer.md) > [ConsoleMessageLocation](./puppeteer.consolemessagelocation.md)
+
+## ConsoleMessageLocation interface
+
+
+Signature:
+
+```typescript
+export interface ConsoleMessageLocation
+```
+
+## Properties
+
+| Property | Type | Description |
+| --- | --- | --- |
+| [columnNumber](./puppeteer.consolemessagelocation.columnnumber.md) | number | 0-based column number in the resource if known or undefined
otherwise. |
+| [lineNumber](./puppeteer.consolemessagelocation.linenumber.md) | number | 0-based line number in the resource if known or undefined
otherwise. |
+| [url](./puppeteer.consolemessagelocation.url.md) | string | URL of the resource if known or undefined
otherwise. |
+
diff --git a/new-docs/puppeteer.consolemessagelocation.url.md b/new-docs/puppeteer.consolemessagelocation.url.md
new file mode 100644
index 0000000000000..a3cebf3f6c23c
--- /dev/null
+++ b/new-docs/puppeteer.consolemessagelocation.url.md
@@ -0,0 +1,13 @@
+
+
+[Home](./index.md) > [puppeteer](./puppeteer.md) > [ConsoleMessageLocation](./puppeteer.consolemessagelocation.md) > [url](./puppeteer.consolemessagelocation.url.md)
+
+## ConsoleMessageLocation.url property
+
+URL of the resource if known or `undefined` otherwise.
+
+Signature:
+
+```typescript
+url?: string;
+```
diff --git a/new-docs/puppeteer.consolemessagetype.md b/new-docs/puppeteer.consolemessagetype.md
new file mode 100644
index 0000000000000..17e537561c506
--- /dev/null
+++ b/new-docs/puppeteer.consolemessagetype.md
@@ -0,0 +1,13 @@
+
+
+[Home](./index.md) > [puppeteer](./puppeteer.md) > [ConsoleMessageType](./puppeteer.consolemessagetype.md)
+
+## ConsoleMessageType type
+
+The supported types for console messages.
+
+Signature:
+
+```typescript
+export declare type ConsoleMessageType = 'log' | 'debug' | 'info' | 'error' | 'warning' | 'dir' | 'dirxml' | 'table' | 'trace' | 'clear' | 'startGroup' | 'startGroupCollapsed' | 'endGroup' | 'assert' | 'profile' | 'profileEnd' | 'count' | 'timeEnd' | 'verbose';
+```
diff --git a/new-docs/puppeteer.md b/new-docs/puppeteer.md
index 7310739d8c2a6..e3063b01199b2 100644
--- a/new-docs/puppeteer.md
+++ b/new-docs/puppeteer.md
@@ -14,7 +14,7 @@
| [BrowserFetcher](./puppeteer.browserfetcher.md) | |
| [CDPSession](./puppeteer.cdpsession.md) | The CDPSession
instances are used to talk raw Chrome Devtools Protocol. |
| [Connection](./puppeteer.connection.md) | |
-| [ConsoleMessage](./puppeteer.consolemessage.md) | |
+| [ConsoleMessage](./puppeteer.consolemessage.md) | ConsoleMessage objects are dispatched by page via the 'console' event. |
| [Coverage](./puppeteer.coverage.md) | |
| [Dialog](./puppeteer.dialog.md) | Dialog instances are dispatched by the [Page](./puppeteer.page.md) via the dialog
event. |
| [ElementHandle](./puppeteer.elementhandle.md) | |
@@ -54,6 +54,7 @@
| Interface | Description |
| --- | --- |
| [BrowserFetcherOptions](./puppeteer.browserfetcheroptions.md) | |
+| [ConsoleMessageLocation](./puppeteer.consolemessagelocation.md) | |
| [SerializedAXNode](./puppeteer.serializedaxnode.md) | Represents a Node and the properties of it that are relevant to Accessibility. |
| [SnapshotOptions](./puppeteer.snapshotoptions.md) | |
@@ -68,6 +69,7 @@
| Type Alias | Description |
| --- | --- |
+| [ConsoleMessageType](./puppeteer.consolemessagetype.md) | The supported types for console messages. |
| [MouseButtonInput](./puppeteer.mousebuttoninput.md) | |
| [PuppeteerErrors](./puppeteer.puppeteererrors.md) | |
diff --git a/src/common/ConsoleMessage.ts b/src/common/ConsoleMessage.ts
index 1e19b18c45820..44968a7a9de2f 100644
--- a/src/common/ConsoleMessage.ts
+++ b/src/common/ConsoleMessage.ts
@@ -16,20 +16,55 @@
import { JSHandle } from './JSHandle';
-interface ConsoleMessageLocation {
+/**
+ * @public
+ */
+export interface ConsoleMessageLocation {
+ /**
+ * URL of the resource if known or `undefined` otherwise.
+ */
url?: string;
+
+ /**
+ * 0-based line number in the resource if known or `undefined` otherwise.
+ */
lineNumber?: number;
+
+ /**
+ * 0-based column number in the resource if known or `undefined` otherwise.
+ */
columnNumber?: number;
}
+// Prettier seems to struggle with the ConsoleMessageType declaration
+// so it is switched off just for that block.
+/* eslint-disable prettier/prettier */
+
+/**
+ * The supported types for console messages.
+ */
+export type ConsoleMessageType = 'log' | 'debug' | 'info' | 'error' | 'warning' |
+ 'dir' | 'dirxml' | 'table' | 'trace' | 'clear' | 'startGroup' |
+ 'startGroupCollapsed' | 'endGroup' | 'assert' | 'profile' |
+ 'profileEnd' | 'count' | 'timeEnd' | 'verbose';
+
+/* eslint-enable prettier/prettier */
+
+/**
+ * ConsoleMessage objects are dispatched by page via the 'console' event.
+ * @public
+ */
export class ConsoleMessage {
- private _type: string;
+ private _type: ConsoleMessageType;
private _text: string;
private _args: JSHandle[];
private _location: ConsoleMessageLocation;
+ /**
+ * @public
+ */
constructor(
- type: string,
+ type: ConsoleMessageType,
text: string,
args: JSHandle[],
location: ConsoleMessageLocation = {}
@@ -40,18 +75,30 @@ export class ConsoleMessage {
this._location = location;
}
- type(): string {
+ /**
+ * @returns The type of the console message.
+ */
+ type(): ConsoleMessageType {
return this._type;
}
+ /**
+ * @returns The text of the console message.
+ */
text(): string {
return this._text;
}
+ /**
+ * @returns An array of arguments passed to the console.
+ */
args(): JSHandle[] {
return this._args;
}
+ /**
+ * @returns The location of the console message.
+ */
location(): ConsoleMessageLocation {
return this._location;
}
diff --git a/src/common/Page.ts b/src/common/Page.ts
index 963fd515ca2d6..a8d184ea549c2 100644
--- a/src/common/Page.ts
+++ b/src/common/Page.ts
@@ -38,7 +38,7 @@ import { HTTPResponse } from './HTTPResponse';
import { Accessibility } from './Accessibility';
import { TimeoutSettings } from './TimeoutSettings';
import { FileChooser } from './FileChooser';
-import { ConsoleMessage } from './ConsoleMessage';
+import { ConsoleMessage, ConsoleMessageType } from './ConsoleMessage';
import { PuppeteerLifeCycleEvent } from './LifecycleWatcher';
import Protocol from '../protocol';
@@ -775,7 +775,7 @@ export class Page extends EventEmitter {
}
private _addConsoleMessage(
- type: string,
+ type: ConsoleMessageType,
args: JSHandle[],
stackTrace?: Protocol.Runtime.StackTrace
): void {