Created
November 6, 2017 04:02
-
-
Save lejeunerenard/56d468fdf0d3478fca3c69745146fc3d to your computer and use it in GitHub Desktop.
Drop in logging solution for debugging where DevTools isn't available.
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
var lastMsg | |
function exlog (text) { | |
var popup = document.getElementById('xlog-popup') | |
if (!popup) { | |
popup = document.createElement('div') | |
Object.assign(popup.style, { | |
width: '100%', | |
height: '100%', | |
top: 0, | |
left: 0, | |
position: 'absolute', | |
zIndex: 1000000, | |
padding: '20px', | |
pointerEvents: 'none', | |
background: 'rgba(255, 255, 255, 0.5)' | |
}) | |
popup.setAttribute('id', 'xlog-popup') | |
document.body.appendChild(popup) | |
} | |
if (lastMsg === text) { | |
var msg = document.getElementById('xlog-popup').querySelector('p:last-child') | |
var counter = msg.querySelector('span') | |
if (!counter) { | |
counter = document.createElement('span') | |
counter.style.paddingLeft = '10px' | |
msg.appendChild(counter) | |
} | |
counter.innerText = (parseInt(counter.innerText) || 0) + 1 | |
} else { | |
var msg = document.createElement('p') | |
Object.assign(msg.style, { | |
color: '#c00', | |
fontSize: '20px' | |
}) | |
msg.innerText = text | |
lastMsg = text | |
popup.appendChild(msg) | |
} | |
} | |
window.onerror = function errorExlog (err, source, lineno, colno, error) { | |
exlog('Error: ' + err + ' source: ' + source + ' line#' + lineno + ':' + colno + ' : ' + error) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment