JSFiddle - React, Tailwind, and code Playground
JavaScript
$(document).ready(function() {
function getLogLocation() {
var ua = navigator.userAgent;
var isFF = ua.search(/firefox/i) !== -1 ? true : false;
var isChrome = ua.search(/chrome/i) !== -1 ? true : false;
if (isFF || isChrome) {
var stack = Error().stack,
cname = '',
funcPattern,
classPattern = /.*\/(.*)\.js/; // looking for something between the last backslash and .js
if (stack) {
var stacks = stack.split('\n');
if (stacks) {
var theStack;
// the browsers create the stack string differently
if (isChrome) {
// the stack has getClassName, then logMessage, then our calling class, but Chrome has some added garbage
theStack = stacks[3];
funcPattern = /at\s(.*)\s+\(/; // looking for something between a period and the first paren
}
else {
theStack = stacks[1];
funcPattern = /^\.*(.*)\@/; // looking for something between a period and an @ symbol
}
var matches = theStack.match(classPattern);
cname = matches[1] + '::';
matches = theStack.match(funcPattern);
cname += matches[1] + ':';
}
}
return cname;
}
}
function blah() {
var cname = getLogLocation();
alert(cname);
}
blah();
});