Bringing back the console API on Netflix and Facebook

Facebook and Netflix have implemented some code that breaks the console API in Chrome by changing the getter/setter for the console property on the window object. The purpose is noble – to help avoid a social engineering attack - but as a developer it irks me. I want my console when and where I want it.  In short order, Zach and I had a fix in place that unbreaks the console.

Using dotjs – which I’ve written about at Gigaom Kitchen - we can run the following code before the console-breaking code executes (here’s my dotjs file):

var s = document.createElement('script');
s.innerHTML = 'Object.defineProperty(window, "console", {writable: false});';
document.head.appendChild( s );

MDN writes on the writable property:

When the writable property attribute is set to false, the property is said to be “non-writable”. It cannot be reassigned.

Now I get my console :)