diff --git a/docs/api.md b/docs/api.md
index e8b11513..9bf339e2 100644
--- a/docs/api.md
+++ b/docs/api.md
@@ -214,6 +214,7 @@
- [class: ConsoleMessage](#class-consolemessage)
* [consoleMessage.args()](#consolemessageargs)
* [consoleMessage.location()](#consolemessagelocation)
+ * [consoleMessage.stackTrace()](#consolemessagestacktrace)
* [consoleMessage.text()](#consolemessagetext)
* [consoleMessage.type()](#consolemessagetype)
- [class: Frame](#class-frame)
@@ -2752,6 +2753,12 @@ const puppeteer = require('puppeteer');
- `lineNumber` <[number]> 0-based line number in the resource if known or `undefined` otherwise.
- `columnNumber` <[number]> 0-based column number in the resource if known or `undefined` otherwise.
+#### consoleMessage.stackTrace()
+- returns: <[Array]<[Object]>>
+ - `url` <[string]> URL of the resource if known or `undefined` otherwise.
+ - `lineNumber` <[number]> 0-based line number in the resource if known or `undefined` otherwise.
+ - `columnNumber` <[number]> 0-based column number in the resource if known or `undefined` otherwise.
+
#### consoleMessage.text()
- returns: <[string]>
diff --git a/new-docs/puppeteer.consolemessage._constructor_.md b/new-docs/puppeteer.consolemessage._constructor_.md
index 79ca5dfa..f362981a 100644
--- a/new-docs/puppeteer.consolemessage._constructor_.md
+++ b/new-docs/puppeteer.consolemessage._constructor_.md
@@ -9,7 +9,7 @@ Constructs a new instance of the `ConsoleMessage` class
Signature:
```typescript
-constructor(type: ConsoleMessageType, text: string, args: JSHandle[], location?: ConsoleMessageLocation);
+constructor(type: ConsoleMessageType, text: string, args: JSHandle[], stackTraceLocations: ConsoleMessageLocation[]);
```
## Parameters
@@ -19,5 +19,5 @@ constructor(type: ConsoleMessageType, text: string, args: JSHandle[], location?:
| type | [ConsoleMessageType](./puppeteer.consolemessagetype.md) | |
| text | string | |
| args | [JSHandle](./puppeteer.jshandle.md)\[\] | |
-| location | [ConsoleMessageLocation](./puppeteer.consolemessagelocation.md) | |
+| stackTraceLocations | [ConsoleMessageLocation](./puppeteer.consolemessagelocation.md)\[\] | |
diff --git a/new-docs/puppeteer.consolemessage.md b/new-docs/puppeteer.consolemessage.md
index 0b3f84a0..446d75b5 100644
--- a/new-docs/puppeteer.consolemessage.md
+++ b/new-docs/puppeteer.consolemessage.md
@@ -16,7 +16,7 @@ export declare class ConsoleMessage
| Constructor | Modifiers | Description |
| --- | --- | --- |
-| [(constructor)(type, text, args, location)](./puppeteer.consolemessage._constructor_.md) | | Constructs a new instance of the ConsoleMessage
class |
+| [(constructor)(type, text, args, stackTraceLocations)](./puppeteer.consolemessage._constructor_.md) | | Constructs a new instance of the ConsoleMessage
class |
## Methods
@@ -24,6 +24,7 @@ export declare class ConsoleMessage
| --- | --- | --- |
| [args()](./puppeteer.consolemessage.args.md) | | |
| [location()](./puppeteer.consolemessage.location.md) | | |
+| [stackTrace()](./puppeteer.consolemessage.stacktrace.md) | | |
| [text()](./puppeteer.consolemessage.text.md) | | |
| [type()](./puppeteer.consolemessage.type.md) | | |
diff --git a/new-docs/puppeteer.consolemessage.stacktrace.md b/new-docs/puppeteer.consolemessage.stacktrace.md
new file mode 100644
index 00000000..7c080c79
--- /dev/null
+++ b/new-docs/puppeteer.consolemessage.stacktrace.md
@@ -0,0 +1,17 @@
+
+
+[Home](./index.md) > [puppeteer](./puppeteer.md) > [ConsoleMessage](./puppeteer.consolemessage.md) > [stackTrace](./puppeteer.consolemessage.stacktrace.md)
+
+## ConsoleMessage.stackTrace() method
+
+Signature:
+
+```typescript
+stackTrace(): ConsoleMessageLocation[];
+```
+Returns:
+
+[ConsoleMessageLocation](./puppeteer.consolemessagelocation.md)\[\]
+
+The array of locations on the stack of the console message.
+
diff --git a/src/common/ConsoleMessage.ts b/src/common/ConsoleMessage.ts
index 7b772dc4..3387dc59 100644
--- a/src/common/ConsoleMessage.ts
+++ b/src/common/ConsoleMessage.ts
@@ -68,7 +68,7 @@ export class ConsoleMessage {
private _type: ConsoleMessageType;
private _text: string;
private _args: JSHandle[];
- private _location: ConsoleMessageLocation;
+ private _stackTraceLocations: ConsoleMessageLocation[];
/**
* @public
@@ -77,12 +77,12 @@ export class ConsoleMessage {
type: ConsoleMessageType,
text: string,
args: JSHandle[],
- location: ConsoleMessageLocation = {}
+ stackTraceLocations: ConsoleMessageLocation[]
) {
this._type = type;
this._text = text;
this._args = args;
- this._location = location;
+ this._stackTraceLocations = stackTraceLocations;
}
/**
@@ -110,6 +110,13 @@ export class ConsoleMessage {
* @returns The location of the console message.
*/
location(): ConsoleMessageLocation {
- return this._location;
+ return this._stackTraceLocations.length ? this._stackTraceLocations[0] : {};
+ }
+
+ /**
+ * @returns The array of locations on the stack of the console message.
+ */
+ stackTrace(): ConsoleMessageLocation[] {
+ return this._stackTraceLocations;
}
}
diff --git a/src/common/Page.ts b/src/common/Page.ts
index 44827972..4000415c 100644
--- a/src/common/Page.ts
+++ b/src/common/Page.ts
@@ -605,7 +605,7 @@ export class Page extends EventEmitter {
if (source !== 'worker')
this.emit(
PageEmittedEvents.Console,
- new ConsoleMessage(level, text, [], { url, lineNumber })
+ new ConsoleMessage(level, text, [], [{ url, lineNumber }])
);
}
@@ -1230,19 +1230,21 @@ export class Page extends EventEmitter {
if (remoteObject.objectId) textTokens.push(arg.toString());
else textTokens.push(helper.valueFromRemoteObject(remoteObject));
}
- const location =
- stackTrace && stackTrace.callFrames.length
- ? {
- url: stackTrace.callFrames[0].url,
- lineNumber: stackTrace.callFrames[0].lineNumber,
- columnNumber: stackTrace.callFrames[0].columnNumber,
- }
- : {};
+ const stackTraceLocations = [];
+ if (stackTrace) {
+ for (const callFrame of stackTrace.callFrames) {
+ stackTraceLocations.push({
+ url: callFrame.url,
+ lineNumber: callFrame.lineNumber,
+ columnNumber: callFrame.columnNumber,
+ });
+ }
+ }
const message = new ConsoleMessage(
type,
textTokens.join(' '),
args,
- location
+ stackTraceLocations
);
this.emit(PageEmittedEvents.Console, message);
}
diff --git a/test/assets/consolelog.html b/test/assets/consolelog.html
index 7fa1b211..4a27803a 100644
--- a/test/assets/consolelog.html
+++ b/test/assets/consolelog.html
@@ -5,7 +5,13 @@