Skip to content

Instantly share code, notes, and snippets.

@coderofsalvation
Created August 6, 2018 19:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coderofsalvation/fdc7c8c736d9fdd7a153d18a7b82512e to your computer and use it in GitHub Desktop.
Save coderofsalvation/fdc7c8c736d9fdd7a153d18a7b82512e to your computer and use it in GitHub Desktop.
easy debugging for touch devices
// easy debugging on touch devices:
// put 3 fingers on the screen to activate it
var debug = function(){
if( ( /(android|iphone|ipad)/gi ).test( navigator.appVersion ) ) {
var actived = false
var log = console && console.log ? console.log.bind(console) : function(){}
console = console || {}
console._log = []
console.log = function() {
var arr = []
var str = ""
for ( var i = 0; i < arguments.length; i++ ) {
str += String(arguments[ i ])
arr.push( arguments[ i ] )
}
console._log.push( arr.join( ", ") )
log( String(str) )
}
console.trace = function(){
var stack
try {
throw new Error()
} catch( ex ) {
stack = ex.stack
}
console.log( "console.trace()\n" + stack.split( "\n" ).slice( 2 ).join( " \n" ) )
}
console.dir = function( obj ) {
try{
console.log(JSON.stringify(obj, null, 2))
}catch(e){}
}
console.show = function(){
alert( this._log.join( "\n" ) )
this._log = []
}
console.warn = console.log
window.onerror = function( msg, url, line ) {
console.log("ERROR: \"" + msg + "\" at line " + line + " in "+url)
}
window.addEventListener( "touchstart", function( e ) {
if( e.touches.length === 3 ) console.show()
})
}
}
if (typeof module !== 'undefined' && typeof module.exports !== 'undefined'){
module.exports = debug
} else{
new debug()
if( !console.error ) console.error = console.log
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment