Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chrome extension console.log override

I'm building a chrome extension that reads the console log and find where an ip appears, after the string "Connecting to", and gets the ip.

store = []; 
var oldf = console.log; 
console.log = function(){   
store.push(arguments);    
oldf.apply(console, arguments);
};

pos = 0 
server = ""

setTimeout(function(){
    for(i = 0; i < store.length; i++){
        if(store[i][0].indexOf("Connecting to") != -1){
             pos = i
        }
    }
    var goal = store[pos][0].split(" ")[self.length-1];
    server = goal
    console.log(server);
  }, 3000);

I have tried this code with Tampermonkey and works ok, but as chrome extension it doesn't work.The override for the console.log function works right so it might be something about permissions with the chrome extension. Is my first so I don't know much about. I get Uncaught TypeError: Cannot read property '0' of undefined If you need anything else just tell me

like image 226
Yábir Garcia Avatar asked Dec 18 '25 12:12

Yábir Garcia


1 Answers

The reason is because Tampermonkey injects code into a site's document, whereas in Chrome Extension no, if you do this, you edit Chrome extension's console. To do this, you should use a method to inject the script, you can see here

like image 161
Walter Chapilliquen - wZVanG Avatar answered Dec 21 '25 02:12

Walter Chapilliquen - wZVanG