Last active
August 29, 2015 13:57
-
-
Save purplecabbage/4571cc93a913eb8e593e to your computer and use it in GitHub Desktop.
Get js stack trace from exception
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 () { | |
var locStr = window.location.toString(); | |
// we will want to clean up the full path for iOS ... | |
var splitStr = locStr.substring("file://", locStr.lastIndexOf("/") - 1); | |
console.trace = function () { | |
try { | |
throw new Error(); | |
} catch (e) { | |
// skip the first 2 items, they will be the error we just threw and info on this very function | |
if (e.stack) { | |
var cleanStack = e.stack.split("\n").slice(2); | |
for (var n = 0; n < cleanStack.length; n++) { | |
cleanStack[n] = cleanStack[n].split(splitStr).join(""); | |
} | |
this.log(cleanStack.join("\n")); | |
} | |
} | |
} | |
})(); | |
var testFunk = function () { | |
console.trace(); | |
} | |
function callMe() { | |
testFunk(); | |
} | |
document.addEventListener('deviceready', function iAmFunky(){ | |
callMe(); | |
}, false); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
iOS 7.1 output:
stack =
callMe@file:///Users/shaz/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/F40363A6-5AFE-4E19-8125-A1A4C928595D/HelloCordova.app/www/js/index.js:12:13
iAmFunky@file:///Users/shaz/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/F40363A6-5AFE-4E19-8125-A1A4C928595D/HelloCordova.app/www/js/index.js:26:33
fire@file:///Users/shaz/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/F40363A6-5AFE-4E19-8125-A1A4C928595D/HelloCordova.app/www/cordova.js:750:28
file:///Users/shaz/Library/Application%20Support/iPhone%20Simulator/7.1/Applications/F40363A6-5AFE-4E19-8125-A1A4C928595D/HelloCordova.app/www/cordova.js:223:53