3

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

Yábir Garcia
  • 329
  • 3
  • 17
  • this code `store[pos][0].split(" ")[self.length-1]` will run even when `store.length === 0`, which is probably whats causing the error. – levi Jun 05 '15 at 20:09
  • @levi It is not the reason almost here of the error cause the expectated output is the output. The error comes when I run the code as a chrome-extension where the expectated output is not the output. – Yábir Garcia Jun 05 '15 at 20:13

1 Answers1

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

Community
  • 1
  • 1