JavaScript执行错误

JavaScript执行错误在Fundebug控制台的图标如下:

JavaScript 执行错误 - 图1

由于拼写失误,测试不完善,或者是意外的边界条件,JavaScript代码在用户浏览器中执行时,有可能会出错。

下面的示例中,alert被写成了aler,因此会报ReferenceError:

  1. aler("hello");

Fundebug插件捕获的这个错误之后,开发者将受到报警,然后可以在我们的控制台查看错误详情:

JavaScript 执行错误 - 图2

Fundebug插件捕获的错误数据如下:

  1. {
  2. "notifierVersion": "0.2.0",
  3. "userAgent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:54.0) Gecko/20100101 Firefox/54.0",
  4. "locale": "zh",
  5. "url": "http://localhost:4000",
  6. "title": "Test",
  7. "apiKey": "API-KEY",
  8. "name": "ReferenceError",
  9. "time": 1502863944724,
  10. "message": "Uncaught ReferenceError: aler is not defined",
  11. "fileName": "http://localhost:4000/test.js",
  12. "lineNumber": 1,
  13. "columnNumber": 1,
  14. "stacktrace": "@http://localhost:4000/test.js:1:1\n",
  15. "type": "uncaught",
  16. "severity": "error"
  17. }

JavaScript执行错误type属性值分为caught或者uncaught两种,caughtnotifyError发送的错误,而uncaught为Fundebug插件自动捕获的错误。