Yábir Garcia
Yábir Garcia

Reputation: 339

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

Upvotes: 3

Views: 975

Answers (1)

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

Upvotes: 1

Related Questions