I'm doing some studies in Javascript using Twitter website as example. In any website i can open Google Devtools and use the console to manipulate anything on the page, such as get DOM nodes, edit elements and so on.
For instance, when i open 'www.google', go to Devtools and type the mand above :
console.log('testing');
I get 'testing' string showing in the console.
However, when i open 'www.twitter' and do the same thing, NOTHING happens. Nothing is shown in console, just an 'undefined' string as shown below :
Why this behaviour happens only on Twitter website ?
EDIT : Tried the solution proposed on "delete" - restore native function not working for changed prototype, how then?
But did not work :
I'm doing some studies in Javascript using Twitter website as example. In any website i can open Google Devtools and use the console to manipulate anything on the page, such as get DOM nodes, edit elements and so on.
For instance, when i open 'www.google.', go to Devtools and type the mand above :
console.log('testing');
I get 'testing' string showing in the console.
However, when i open 'www.twitter.' and do the same thing, NOTHING happens. Nothing is shown in console, just an 'undefined' string as shown below :
Why this behaviour happens only on Twitter website ?
EDIT : Tried the solution proposed on "delete" - restore native function not working for changed prototype, how then?
But did not work :
Share Improve this question edited Jan 9, 2018 at 12:13 delphirules asked Jan 9, 2018 at 11:47 delphirulesdelphirules 7,50818 gold badges69 silver badges131 bronze badges 3-
1
they have probably overriden the method
window.console.log
so that it outputs nothing.. (theundefined
is normal, it's just the evaluation of the whole expression) – Kaddath Commented Jan 9, 2018 at 11:49 - I did not changed anything, i just open Twitter and type the mand ; you can test yourself and simulate the issue. – delphirules Commented Jan 9, 2018 at 11:56
- 1 my ment says "they", not "you" ;) – Kaddath Commented Jan 9, 2018 at 11:59
2 Answers
Reset to default 8In Javascript you can modify your global objects, so it's possible for you to do something like
Array.prototype.push = function(element) {
this[this.length] = 'blah'
}
Now every time you add a element to any array it will always add 'blah';
const myArray = [];
myArray.push(1);
myArray.push(2);
myArray.push(3);
console.log(myArray);
// output ['blah', 'blah', 'blah']
In the twitter website they did the same, although the code is minified you can see it here:
, Y = ["log", "warn", "debug", "info"]
, K = function() {}
, Q = ""
Line 1414 file https://abs.twimg./k/en/init.en.caa653749241467e7dbb.js
To make it work again, copy each line and run it on your console (credits for this solution to Rob W):
var frame = document.createElement('iframe');
document.body.appendChild(frame);
console = frame.contentWindow.console
console.log('it works')
If you type in just console.log
(without any brackets), you can list the code for the log function on that website. Doing this on Twitter gives you
function (){}
Which is indeed an empty function showing that they've overwritten the default. By contrast, the same on google. gives
function log() { [native code] }
Which is the default.