Skip to content

Conversation

@yanivefraim
Copy link
Contributor

@yanivefraim yanivefraim commented Apr 17, 2018

WIP (I'm working on docs)

Fixes #1939

Question: Do we want to return a LogEntry object, similar to ConsoleMessage? (I guess the answer is yes, just making sure)

@yanivefraim yanivefraim changed the title Feat(Page): Add Log domain entries Feat(Page): Add 'Log' domain entries Apr 17, 2018
@aslushnikov
Copy link
Contributor

Question: Do we want to return a LogEntry object, similar to ConsoleMessage? (I guess the answer is yes, just making sure)

@yanivefraim from user perspective, these all are "console" messages, so I'd rather re-use the "console" event together with "ConsoleMessage" object.

Thanks for checking in.

@yanivefraim
Copy link
Contributor Author

yanivefraim commented Apr 18, 2018

@yanivefraim from user perspective, these all are "console" messages, so I'd rather re-use the "console" event together with "ConsoleMessage" object.

@aslushnikov - agree, I will changed my implementation.

One more question - when using LogEntry, we first have to enable it
As I see it, there are three options:

  1. Enable it by default. This is my current implementation
  2. Ask the user to enable it, if console events are needed (I don't like this option)
  3. Have a solution which will enable Logentry only when user did registered to console event (not sure if this is possible. I was thinking of using ES6 Proxy for that, but it might make the code too complex). WDYT?

** and another comment - as far as I understand my args are not working as expected, yet. I will look for a test case for it

@yanivefraim
Copy link
Contributor Author

I couldn't find a use case where we have args on LogEntry. Any idea? (I want to add such a case for my test)
cc @aslushnikov

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.

I couldn't find a use case where we have args on LogEntry. Any idea? (I want to add such a case for my test)

Looks like there's only one client who reports args - form autofill. We don't have autofill component in headless, so there's no good way to have a test here. However, if you manage to re-use the _onConsoleAPI logic, we'll be fine.

P.S. also check out cs.chromium.org: queries like -f:out f:inspector entryAdded can give valuable insights on inner workings of devtools protocol.

});
});

describe('Page.Events.Log.entryAdded', function() {
Copy link
Contributor

Choose a reason for hiding this comment

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

let's move this to other console tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@aslushnikov - done

await page.goto('about:blank');
let message;
page.on('console', event => message = event);
page.evaluate(async() => fetch('https://example.org/').catch(e => {}));
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: let's use server.EMPTY_PAGEinstead of example.com

Copy link
Contributor Author

@yanivefraim yanivefraim Apr 27, 2018

Choose a reason for hiding this comment

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

Done

lib/Page.js Outdated

_onLogEntryAdded(event) {
const {level, text, args} = event.entry;
this.emit(Page.Events.Console, new ConsoleMessage(level, text, args));
Copy link
Contributor

Choose a reason for hiding this comment

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

args are RemoteObjects here; you'd need to convert these to JSHandles first.

It would be ideal if you can reuse all the logic that's already in page._onConsoleAPI code.

Copy link
Contributor Author

@yanivefraim yanivefraim Apr 27, 2018

Choose a reason for hiding this comment

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

@aslushnikov - I tried reusing page._onConsoleAPI but I found that it does not make much sense:
_onConsoleAPI initialize ConsoleMessage's text from args while Log.entryAdded take the text from event.text (when usually there are no args at all). My question is if we do need args for Log.entryAdded? I can refactor _onConsoleAPI to be compatible for both cases (taking text from args or from event.text), but because I don't have a test case for Log.entryAdded with args, I cannot really tell if this use case is working.

WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

@yanivefraim I see. Let's just disregard entryAdded arguments. You can release them like console does.

https://github.com/GoogleChrome/puppeteer/blob/f797f8c307ff5380c750d3851c0b3d61a5299df5/lib/Page.js#L434-L437

I also figured there's no executionContextId in the Log.entryAdded, so you won't be able to convert these args to JSHandles anyway.

Copy link
Contributor Author

@yanivefraim yanivefraim Apr 27, 2018

Choose a reason for hiding this comment

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

@aslushnikov - thanks - fixed (I hope that I understood you correct)

BTW, I noticed event.args.map(arg => helper.releaseObject(this._client, arg)); (in here) does not wait for promise to be resolved. I assume it is because we do not care about the response? (just making sure)

Copy link
Contributor

Choose a reason for hiding this comment

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

BTW, I noticed event.args.map(arg => helper.releaseObject(this._client, arg)); (in here) does not wait for promise to be resolved. I assume it is because we do not care about the response? (just making sure)

That's right

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.

2 participants