# 前端错误监控与错误上报

推荐阅读《前端错误监控指南》 (opens new window)

即时运行错误的捕获方式:

  1. try catch
  2. window.onerror

资源加载错误:

  1. object.onerror
  2. performance.getEntries()
  3. Error事件捕获

上报错误的基本原理:

  1. 采用ajax通信上报
  2. 利用image对象上报

跨域的js运行错误可以捕获Script error,需要2个条件

  1. 相关的js文件上加上Access-Control-Allow-Origin:*的response header
  2. 引用相关的js文件时加上crossorigin属性