Access browser console Logs from within Browser library

Hi again,

I’m looking for way how to capture console logs from browser. I need to get informations that are stored there.

I tried to do something like:

async function captureLogs(page, logger) {
  logger("Did I run?")
  page.on("console", (message) => {
exports.__esModule = true; 
exports.captureLogs = captureLogs;

So I created custom library, that should do the magic (according to internet :slight_smile: )
But I ended that this custom JS keyword is working, but it works only at the moment, when it is called.

Is there any possibility to catch console event and do my own job with it? I know that I can use HAR file to get network ‘tab’, with all request responses, but in console our application is writing lot of debug information, that is good to know after some failure.

I just can’t access them. For me the best way should be to somehow access this tab via chrome developer tools (I this only for chrome) … or maybe to do some kind of ‘background job’ to just catch console events, and do whatever I need to do with them.

TO be honest I didn’t find any working solution for this. This one is the closest that I get to, but unfortunately it does not read the console log backwards and also, it is working only in the time, that I call the keyword. It is not ‘listening in the background’ and doing its job.


I am struggling with this too - gone through those exacts steps with the exact same results…

Might be of interests… the marked solution is with seleniumlibrary, but you could switch the keywords used to browser libraries wording where needed, not tried it myself:

1 Like

Hi! Did you manage to find a solution? :slight_smile: