Created
July 11, 2012 22:06
-
-
Save jwalsh/3094001 to your computer and use it in GitHub Desktop.
This file contains 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
(function(global, undefined) { | |
// Protect and log errors | |
try { | |
var log = (typeof console.log === 'function') ? | |
console.log : | |
function(m) {}; | |
var MAXDEPTH = 2; | |
// name, prefix, depth | |
var print = function(n, p, d) { | |
try { | |
var b = p[n]; | |
// console.log(n, b, d); | |
// Allow base indenting based on the depth | |
var response = '\n' + | |
(new Array(d).join(' ')) + | |
n + | |
' (' + (typeof b) + ')'; | |
// Only check after we've summarized the object name | |
if (d >= MAXDEPTH) { | |
return true; | |
} | |
// Could apply hasOwnProperty filter | |
// This doesn't account for functions with child properties | |
// Don't iterate through the lenght of the string | |
// We don't need all objects if there are third party libraries | |
if (typeof b === 'object') { | |
for (var k in b) { | |
if (b.hasOwnProperty(k)) { | |
response += print(k, b, d + 1); | |
} | |
} | |
} | |
} catch (x) { | |
} finally { | |
return response; | |
} | |
}; | |
var body = document.getElementsByTagName('body')[0]; | |
// Establish a baseline of an unpolluted namespace in a new frame | |
var frame = document.createElement('frame'); | |
frame.src = '/blank.html'; | |
body.appendChild(frame); | |
var clean = parent.frames[0]; | |
var output = ''; | |
for (var p in window) { | |
if (typeof clean.window[p] === 'undefined') { | |
if (typeof window[p] !== 'undefined') { | |
output += print(p, window, 1); | |
} | |
} | |
}; | |
var report = document.createElement('pre'); | |
var style = "position: fixed; top: 0; right: 0; " + | |
"opacity:0.6; border-radius: 10px;" + | |
"overflow: hidden; " + | |
"border: 2px solid #ccc; background: #222; color: #fff;" + | |
"margin: 10px; padding: 15px;"; | |
report.setAttribute("style", style); | |
report.innerHTML = output; | |
body.appendChild(report); | |
} catch (x) { | |
try { | |
// console.log(x); | |
var img = document.createElement('img'); | |
img.src = 'http://wal.sh/bug/img.php?error=true'; | |
img.className = '⚠'; | |
document.getElementsByTagName('body')[0].appendChild(img); | |
} catch (x) { | |
} | |
} | |
}(this)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment