How to get Extension to read specific part of console in Chrome?

I wanna create a Chrome extension that needs to read a specific part which the website posts into the console. Here you can see this part:

Picture of the part in console

I need specifically the "questionsList" part.

How do I do that in the JS of my Extension?

1 thought on “How to get Extension to read specific part of console in Chrome?”

  1. As the other user said, overriding the console.log method will be the easier way. You can then iterate over the arguments passed in to the console.log function and see if one of the arguments is an object that has a property named "questionList", and if it does it should store its value in a global object named questionList. You can inject this code in the console:

    let oldConsole=window.console
    let questionList=[];
    let console=(function(oldConsole){
           return {
                 log:function(...args){
                     oldConsole.log(...args)
                    for(arg of args){
                      if(typeof arg==="object" && "questionList" in arg){
                        questionList=arg["questionList"]   
                      }
                    }
                 },
                 error:function(...args){
                   oldConsole.error(...args)
                 }
               }
    })(oldConsole);
    

    Now whenever the console logs that particular object you can access this array from the questionList global variable.

    Reply

Leave a Comment