Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

alias to chrome console.log

Tags:

I would like to know why the follow code doesn't work in the Google Chrome:

// creates a xss console log  var cl = ( typeof( console ) != 'undefined' ) ? console.log : alert; cl('teste'); 

output: Uncaught TypeError: Illegal invocation

thanks.

like image 451
augustowebd Avatar asked Feb 27 '11 14:02

augustowebd


2 Answers

https://groups.google.com/a/chromium.org/d/msg/chromium-bugs/gGVPJ1T-qA0/F8uSupbO2R8J

Apparently you can also defined log:

 log = console.log.bind(console); 

and then the line numbers also work

like image 82
Ben West Avatar answered Oct 05 '22 01:10

Ben West


When you write cl();, you're calling log in the global context.

Chrome's console.log doesn't want to be called on the window object.

Instead, you can write

cl = function() { return console.log.apply(console, arguments); }; 

This will call log in the context of console.

like image 30
SLaks Avatar answered Oct 05 '22 02:10

SLaks