Skip to content
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 2 commits into from Jan 11, 2019

Conversation

tompere
Copy link
Contributor

@tompere tompere commented Oct 8, 2018

This patch add additional method to ConsoleMessage object sent on console event. Currently, added URL and line number to additionalInfo.

Fixes #3029

@@ -179,11 +179,11 @@ class Page extends EventEmitter {
* @param {!Protocol.Log.entryAddedPayload} event
*/
_onLogEntryAdded(event) {
Copy link
Collaborator

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.

Copy link
Contributor Author

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 to ExceptionDetails

Copy link
Collaborator

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

docs/api.md Outdated
@@ -2168,6 +2169,11 @@ puppeteer.launch().then(async browser => {

[ConsoleMessage] objects are dispatched by page via the ['console'](#event-console) event.

#### consoleMessage.additionalInfo()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just put the url and line number on the console message itself?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you mean extending the api? same as type and args?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

as I commented in the origin issue:

This is under the assumption that additionalInfo is a subset of LogEntry optional params, thus future requests for additional data can easily added

makes sense?

Copy link
Contributor Author

@tompere tompere Oct 8, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also the fact the lineNumber and url are optionals, made me feel less comfortable in adding a dedicated and explicit API (as it will return undefined many times...)

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having additionalInfo raises some difficult questions. Which values are considered core, and which are considered additional? Can additional info be null, or will it be an empty object? Even if we have reasoning, its not obvious to a user of the API. They would have to check the documentation every time.

That being said, it might make sense to group line, column, and url under a location object if they are often all null or all present.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done. location it is.

@tompere tompere force-pushed the fix-3029 branch 4 times, most recently from d283916 to 05878a3 Compare October 11, 2018 19:18
This patch add additional method to ConsoleMessage object sent on console event. Currently, added URL and line number to additionalInfo.

Fixes puppeteer#3029
lib/Page.js Outdated
let location;
if (event.stackTrace && event.stackTrace.callFrames) {
const {url, lineNumber, columnNumber} = event.stackTrace.callFrames[0];
location = {url, lineNumber, columnNumber};
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: don't unconditionally add the properties if they might be undefined. Otherwise a user doing "url" in location will be misled.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a clarification about how defensive puppeteer code should be:

Can i rely on devtools protocol API for optional/mandatory return values?
e.g.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can rely on the values that the protocol will provide, but there might be extra values alongside those values. So you should build your own object instead of serving the raw protocol object.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -517,7 +522,7 @@ class Page extends EventEmitter {
* @param {string} type
* @param {!Array<!Puppeteer.JSHandle>} args
*/
_addConsoleMessage(type, args) {
_addConsoleMessage(type, args, location) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jsdoc

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

This patch add additional method to ConsoleMessage object sent on console event. Currently, added URL and line number to additionalInfo.

Fixes puppeteer#3029
@JoelEinbinder JoelEinbinder changed the title feat(Page): exposed additional info for ConsoleMessage object feat(page): exposed additional info for ConsoleMessage object Oct 17, 2018
Copy link
Contributor

@aslushnikov aslushnikov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In it goes!

@aslushnikov aslushnikov merged commit 0c86763 into puppeteer:master Jan 11, 2019
@tompere
Copy link
Contributor Author

tompere commented Jan 13, 2019

👏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants