# 前端错误监控与错误上报
推荐阅读《前端错误监控指南》 (opens new window)
即时运行错误的捕获方式:
- try catch
- window.onerror
资源加载错误:
- object.onerror
- performance.getEntries()
- Error事件捕获
上报错误的基本原理:
- 采用ajax通信上报
- 利用image对象上报
跨域的js运行错误可以捕获Script error,需要2个条件
- 相关的js文件上加上Access-Control-Allow-Origin:*的response header
- 引用相关的js文件时加上crossorigin属性