filters

通过配置filters属性,用户可以过滤掉一些不需要捕获的错误,例如:

插件版本 >= 0.6.1

  1. fundebug.init(
  2. {
  3. filters: [
  4. {
  5. error: /b is not defined/
  6. }]
  7. })

插件版本 <= 0.5.0

  1. fundebug.filters = [
  2. {
  3. error: /b is not defined/
  4. }]

配置规则

filters属性有以下特点:

  • 它是一个数组,数组中的元素为过滤规则,当错误符合数组中任意一条过滤规则时,则会被过滤
  • 过滤规则是JavaScript对象,该对象的Key为错误的属性名,Value为正则表达式(唯一的特例是”inexistence”);
  • 当错误的属性匹配对应正则表达式时,则会被过滤;
  • 当过滤规则的属性值为”inexistence”时,则会过滤某个属性不存在的错误;

错误事件示例:

测试Fundebug时,在微信开发者工具的调试器中,可以在Network中看到发送到https://fundebug.com/wxjs/的网络请求,这个请求的body就是我们捕获的错误事件

  1. {
  2. "notifierVersion": "0.4.0",
  3. "systemInfo":
  4. {
  5. "errMsg": "getSystemInfo:ok",
  6. "model": "iPhone 5",
  7. "pixelRatio": 2,
  8. "windowWidth": 320,
  9. "windowHeight": 504,
  10. "system": "iOS 10.0.1",
  11. "language": "zh_CN",
  12. "version": "6.6.3",
  13. "screenWidth": 320,
  14. "screenHeight": 568,
  15. "SDKVersion": "1.9.91",
  16. "brand": "devtools",
  17. "fontSizeSetting": 16,
  18. "benchmarkLevel": 1,
  19. "batteryLevel": 100,
  20. "statusBarHeight": 20,
  21. "platform": "devtools"
  22. },
  23. "apikey": "0abbf8337ed309d1e0337ab47a4e904d2ed2a30fcc18d22efd807f190192e24c",
  24. "releaseStage": "production",
  25. "metaData":
  26. {
  27. "tier": "free"
  28. },
  29. "breadcrumbs": [
  30. {
  31. "type": "function",
  32. "time": 1527556801032,
  33. "belong": "App",
  34. "method": "onLaunch",
  35. "path": "pages/start/start",
  36. "query":
  37. {},
  38. "scene": 1001
  39. },
  40. {
  41. "type": "function",
  42. "time": 1527556801328,
  43. "belong": "App",
  44. "method": "onShow",
  45. "path": "pages/start/start",
  46. "query":
  47. {},
  48. "scene": 1001
  49. }],
  50. "time": 1527556801343,
  51. "error": "thirdScriptError\nTEST 01;at App lifeCycleMethod onLaunch function\nError: TEST 01\n at e.onLaunch (http://127.0.0.1:52992/appservice/app.js:19:15)\n at e._0x4c25b0.(anonymous function) (http://127.0.0.1:52992/appservice/release/fundebug.0.3.1.min.js:192:78)\n at e.o (http://127.0.0.1:52992/appservice/__dev__/WAService.js:18:19145)\n at new e (http://127.0.0.1:52992/appservice/__dev__/WAService.js:18:20499)\n at Function.<anonymous> (http://127.0.0.1:52992/appservice/__dev__/WAService.js:18:20988)\n at http://127.0.0.1:52992/appservice/__dev__/WAService.js:17:31961\n at Object._0x27d8dc.(anonymous function) [as bipMe] (http://127.0.0.1:52992/appservice/release/fundebug.0.3.1.min.js:113:12)\n at App (http://127.0.0.1:52992/appservice/release/fundebug.0.3.1.min.js:358:37)\n at http://127.0.0.1:52992/appservice/app.js:16:1\n at require (http://127.0.0.1:52992/appservice/__dev__/WAService.js:18:26712)",
  52. "type": "uncaught",
  53. "scene": 1001
  54. };

配置示例

示例1:过滤ReferenceError的错误

插件版本 >= 0.6.1

  1. fundebug.init(
  2. {
  3. filters: [
  4. {
  5. error: /ReferenceError/
  6. }]
  7. })

插件版本 <= 0.5.0

  1. fundebug.filters = [
  2. {
  3. error: /ReferenceError/
  4. }]

示例2:不监控发送到example.com的GET请求错误

插件版本 >= 0.6.1

  1. fundebug.init(
  2. {
  3. filters: [
  4. {
  5. req:
  6. {
  7. url: /example\.com/,
  8. method: /^GET$/
  9. }
  10. }]
  11. })

插件版本 <= 0.5.0

  1. fundebug.filters = [
  2. {
  3. req:
  4. {
  5. url: /example\.com/,
  6. method: /^GET$/
  7. }
  8. }];

示例3:过滤statusCode为401的HTTP请求错误

插件版本 >= 0.6.1

  1. fundebug.init(
  2. {
  3. filters: [
  4. {
  5. res: {
  6. statusCode: /^401$/
  7. }
  8. }]
  9. })

插件版本 <= 0.5.0

  1. fundebug.filters = [
  2. {
  3. res: {
  4. statusCode: /^401$/
  5. }
  6. }]

示例4:过滤iPhone5上的ReferenceError

插件版本 >= 0.6.1

  1. fundebug.init(
  2. {
  3. filters: [
  4. {
  5. error: /^ReferenceError$/,
  6. systemInfo:
  7. {
  8. "model": /^iPhone 5$/,
  9. }
  10. }]
  11. })

插件版本 <= 0.5.0

  1. fundebug.filters = [
  2. {
  3. error: /^ReferenceError$/,
  4. systemInfo:
  5. {
  6. "model": /^iPhone 5$/,
  7. }
  8. }]

示例5:配置多条过滤规则

插件版本 >= 0.6.1

  1. fundebug.init(
  2. {
  3. filters: [
  4. {
  5. scene: /^1002$/
  6. },
  7. {
  8. error: /TEST 02/,
  9. scene: /1001/
  10. }]
  11. })

插件版本 <= 0.5.0

  1. fundebug.filters = [
  2. {
  3. scene: /^1002$/
  4. },
  5. {
  6. error: /TEST 02/,
  7. scene: /1001/
  8. }];