Skip to content

Instantly share code, notes, and snippets.

@huuyafwww
Created June 6, 2020 09:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save huuyafwww/50cbf18671d66efe7ab5efe321303f76 to your computer and use it in GitHub Desktop.
Save huuyafwww/50cbf18671d66efe7ab5efe321303f76 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>StackTrace</title>
</head>
<body>
<script>
window.onerror = function(msg, file, line, col, err) {
let err_body = (
file + "\n" + "の" +
line + "行目" + col + "文字目から" + "\n" +
msg + "\n" + "というエラーが発生しました"
);
let err_array = {
"msg" : msg,
"file" : file,
"line" : line,
"col" : col
};
alert(
err_body
);
console.log(
err_array
);
};
bar();
</script>
</body>
</html>
@huuyafwww
Copy link
Author

クライアントサイドのエラーをwindow.onerrorで取得する
その他必要な情報を連想配列に追記するなりして、
Ajax等でサーバーサイドに投げて記録するような利用方法がある

@huuyafwww
Copy link
Author

let now_url = location.href;

として現在のページURLを連想配列に加えるなど

@huuyafwww
Copy link
Author

LocalStorage等に操作ログを記録しながら、
タイムスタンプを含めるなど

let now_time = Math.floor(
	new Date()
		.getTime()
	/
	1000
);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment