Created
May 25, 2011 23:29
-
-
Save astorm/992233 to your computer and use it in GitHub Desktop.
Fix console.log in Chrome and Magento
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- Add to the package layout (via local.xml or however you prefer) --> | |
<!-- Also, best to remove before deployment, as some users report --> | |
<!-- it makes IE 7 crash --> | |
<default> | |
<reference name="content"> | |
<block type="core/text" name="fix.console" as="fix.console"> | |
<action method="setText"> | |
<text><![CDATA[<script type="text/javascript"> | |
iframe = document.createElement('iframe'); | |
iframe.style.display = 'none'; | |
document.getElementsByTagName('body')[0].appendChild(iframe); | |
window.console = iframe.contentWindow.console; | |
console.firebug = "faketrue"; | |
</script>]]></text> | |
</action> | |
</block> | |
</reference> | |
</default> |
@ajzele
Ah, that looks more right, it's a pretty hacky fix so I'm not surprised it broke since I first wrote it. Thanks for the fix to my fix.
In case you're curious, the offending Javascript is in
// File js/varien/js.js
if (!("console" in window) || !("firebug" in console))
{
var names = ["log", "debug", "info", "warn", "error", "assert", "dir", "dirxml",
"group", "groupEnd", "time", "timeEnd", "count", "trace", "profile", "profileEnd"];
window.console = {};
for (var i = 0; i < names.length; ++i)
window.console[names[i]] = function() {}
}
in some version of IE8 I had the following error:
Webpage error details User Agent: Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0) Timestamp: Tue, 7 Feb 2012 11:29:49 UTC Message: 'console' is null or not an object Line: 183 Char: 25 Code: 0 URI: Message: HTML Parsing Error: Unable to modify the parent container element before the child element is closed (KB927917) Line: 0 Char: 0 Code: 0 URI:
Adding an "if console" around the javascript in the text node should fix that. It sounds like you're using IE without any javascript debugger.
thx, great snippet! but you need to comment it out after development. besides those errors in IE8 @guymoller mentioned, ie7 crashes completely. if (console) does not fix that.
Thanks for the heads up, but I'm not sure I follow. If you're wrapping everything in an if(console), how does the code run in IE 7?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@alan
In my Google Chrome "iframe.style = 'display:none';" did not work, iframe was visible. Changed it to "iframe.style.display = 'none';" and it worked.
P.S. Thanks for this great snippet. Really saved me :)