-
Notifications
You must be signed in to change notification settings - Fork 9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(page): exposed additional info for ConsoleMessage object #3365
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -179,11 +179,11 @@ class Page extends EventEmitter { | |
* @param {!Protocol.Log.entryAddedPayload} event | ||
*/ | ||
_onLogEntryAdded(event) { | ||
const {level, text, args, source} = event.entry; | ||
const {level, text, args, source, url, lineNumber} = event.entry; | ||
if (args) | ||
args.map(arg => helper.releaseObject(this._client, arg)); | ||
if (source !== 'worker') | ||
this.emit(Page.Events.Console, new ConsoleMessage(level, text)); | ||
this.emit(Page.Events.Console, new ConsoleMessage(level, text, undefined, { url, lineNumber })); | ||
} | ||
|
||
/** | ||
|
@@ -495,7 +495,14 @@ class Page extends EventEmitter { | |
async _onConsoleAPI(event) { | ||
const context = this._frameManager.executionContextById(event.executionContextId); | ||
const values = event.args.map(arg => createJSHandle(context, arg)); | ||
this._addConsoleMessage(event.type, values); | ||
const location = {}; | ||
if (event.stackTrace && event.stackTrace.callFrames) { | ||
const {url, lineNumber, columnNumber} = event.stackTrace.callFrames[0]; | ||
if (url) location.url = url; | ||
if (lineNumber) location.lineNumber = lineNumber; | ||
if (columnNumber) location.columnNumber = columnNumber; | ||
} | ||
this._addConsoleMessage(event.type, values, location); | ||
} | ||
|
||
/** | ||
|
@@ -516,8 +523,9 @@ class Page extends EventEmitter { | |
/** | ||
* @param {string} type | ||
* @param {!Array<!Puppeteer.JSHandle>} args | ||
* @param {ConsoleMessage.Location} location | ||
*/ | ||
_addConsoleMessage(type, args) { | ||
_addConsoleMessage(type, args, location) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. jsdoc There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
if (!this.listenerCount(Page.Events.Console)) { | ||
args.forEach(arg => arg.dispose()); | ||
return; | ||
|
@@ -530,7 +538,7 @@ class Page extends EventEmitter { | |
else | ||
textTokens.push(helper.valueFromRemoteObject(remoteObject)); | ||
} | ||
const message = new ConsoleMessage(type, textTokens.join(' '), args); | ||
const message = new ConsoleMessage(type, textTokens.join(' '), args, location); | ||
this.emit(Page.Events.Console, message); | ||
} | ||
|
||
|
@@ -1124,16 +1132,25 @@ Page.Events = { | |
* @property {("Strict"|"Lax")=} sameSite | ||
*/ | ||
|
||
/** | ||
* @typedef {Object} ConsoleMessage.Location | ||
* @property {string=} url | ||
* @property {number=} lineNumber | ||
* @property {number=} columnNumber | ||
*/ | ||
|
||
class ConsoleMessage { | ||
/** | ||
* @param {string} type | ||
* @param {string} text | ||
* @param {!Array<!Puppeteer.JSHandle>} args | ||
* @param {ConsoleMessage.Location} location | ||
*/ | ||
constructor(type, text, args = []) { | ||
constructor(type, text, args = [], location = {}) { | ||
this._type = type; | ||
this._text = text; | ||
this._args = args; | ||
this._location = location; | ||
} | ||
|
||
/** | ||
|
@@ -1156,6 +1173,13 @@ class ConsoleMessage { | |
args() { | ||
return this._args; | ||
} | ||
|
||
/** | ||
* @return {Object} | ||
*/ | ||
location() { | ||
return this._location; | ||
} | ||
} | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Log Entry Test</title> | ||
</head> | ||
<body> | ||
<script> | ||
fetch('http://wat') | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Log Entry Test</title> | ||
</head> | ||
<body> | ||
<script> | ||
console.warn('wat') | ||
</script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not the only entry point for console messages. There is also Runtime.consoleAPICalled. It has line number and url contained in the stack trace.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you please elaborate?
I'm looking into
Runtime.consoleAPICalled
and I don't see such details, nor a reference toExceptionDetails
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is contained in the callframes of the stacktrace: https://chromedevtools.github.io/devtools-protocol/tot/Runtime#type-CallFrame
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done