<html>
<head>
<script>
function main(){
a = b;
}
window.addEventListener('load', function(){
try {
main()
} catch (e){
proceedException(e)
}
})
</script>
<script src="file.js">
</script>
</head>
<body>
<div id="error">
</div>
</body>
</html>
file.js
function parseStackTrace(stacktrace){
let [_, functionName, fileName, row, __, column] = stacktrace.match(/at\s([^\s]+)\s\((.+?):(\d+)(:(\d+))?\)/)
return [functionName, fileName, row, column]
}
function proceedException(exception){
let [fn, file, row, column] = parseStackTrace(exception.stack),
node = document.createElement('p');
node.innerText = `Ошибка в файле: ${file}, функция <${fn}> на строке ${row}${column ? '(' + column + ' символ)' : ''} ${exception}`;
document.querySelector('#error').appendChild(node);
}
function helper(){
let c = 1, a = b;
}
function onload(){
helper();
}
window.addEventListener('load', function(){
try {
onload()
} catch (e){
proceedException(e)
}
})