-
-
Save purplecabbage/4571cc93a913eb8e593e to your computer and use it in GitHub Desktop.
(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); |
There is already a console.trace native function in iOS. Also, if you re-define console.trace, it should be in your deviceready handler since the console plugin probably will clobber your re-definition.
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
WP8 output:
stack =
at testFunk (x-wmapp0:www/js/index.js:30:5)
at callMe (x-wmapp0:www/js/index.js:35:5)
at iAmFunky (x-wmapp0:www/js/index.js:39:5)
at fire (x-wmapp0:www/cordova.js:750:13)
at Anonymous function (x-wmapp0:www/cordova.js:223:21)