If I visit a URL, I want to be able to see what get's logged to the console and see any errors that might show up in javascript running on that page.
How can I log whatever gets logged to the console?
I've looked through the example wiki but I didn't find what I was looking for.
There are two domains for that: Log and Runtime (Runtime.consoleAPICalled); show me what you've tried.
Thx I just found this comment as well which might be helpful: https://github.com/ChromeDevTools/devtools-protocol/issues/5#issuecomment-332223303
Going to try them out and i'll post back here with my results.
As a beginner it's still little confusing to me what a "domain" actually is. From what I understand CDP() returns a client, which has these domains, but I'm looking for a more introductory write up that talks about what a client actually is.
I got what I wanted by following this example with a few modifications
https://github.com/cyrus-and/chrome-remote-interface/wiki/Log-network-requests
// extract domains
const {Network, Page, Runtime} = client;
// setup handlers
Runtime.consoleAPICalled((entry) => {
console.log("console api called: " + entry.args.map(arg=>arg.value).join(" "));
});
// enable events then start!
Promise.all([
Network.enable(),
Page.enable(),
Runtime.enable()
])
When I included Log.entryAdded() it didn't seem to work. I expected to have duplicate copies of the outputs, one from Runtime.consoleAPICalled() and one from Log.entryAdded() but that wasn't the case, i only saw output from the consoleAPICalled() listener.
Also it's a little confusing to me what enable() actually does. In my experience to date I've been able to use Runtime.evaluate() without having enabled Runtime, so I'm assuming enabling is just for turning on the event listeners? The documentation is very concise (which is generally a good thing) but makes it a little harder for beginners to understand exactly what is happening.(https://chromedevtools.github.io/devtools-protocol/tot/Runtime#method-enable).
I expected to have duplicate copies of the outputs, one from Runtime.consoleAPICalled() and one from Log.entryAdded() but that wasn't the case, i only saw output from the consoleAPICalled() listener.
If I recall correctly Log.entryAdded() shows errors and warning from Chrome (e.g., XSS violations and such), not necessarily coming from the console.* API.
In my experience to date I've been able to use Runtime.evaluate() without having enabled Runtime, so I'm assuming enabling is just for turning on the event listeners?
Yeah, that's the usual case: you enable a domain if you want to receive events from it.
The documentation is very concise (which is generally a good thing) but makes it a little harder for beginners to understand exactly what is happening.
I totally agree with you, unfortunately I'm in no way affiliated with Google, for such kind of complaints/suggestions/questions the devtools-protocol repo is a better place.
awesome thanks!
Most helpful comment
If I recall correctly
Log.entryAdded()shows errors and warning from Chrome (e.g., XSS violations and such), not necessarily coming from theconsole.*API.Yeah, that's the usual case: you enable a domain if you want to receive events from it.
I totally agree with you, unfortunately I'm in no way affiliated with Google, for such kind of complaints/suggestions/questions the devtools-protocol repo is a better place.