1 2 3 4 5 6 7 8 9 10 11
/// Extracts current script file path from artificially generated stack trace function script_path() { try { throw new Error(); } catch (e) { let parts = e.stack.match(/(?:\(|@)(\S+):\d+:\d+/); return parts[1]; } } script_path()