@antglobal/rlog-sdk 0.0.1755855517-dev.9 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/README.md +192 -432
  2. package/dist/esm/index.d.ts +14 -41
  3. package/dist/esm/index.d.ts.map +1 -1
  4. package/dist/esm/index.js +92 -76
  5. package/dist/esm/lib/api.d.ts +10 -0
  6. package/dist/esm/lib/api.d.ts.map +1 -1
  7. package/dist/esm/lib/api.js +58 -35
  8. package/dist/esm/lib/config.d.ts +13 -6
  9. package/dist/esm/lib/config.d.ts.map +1 -1
  10. package/dist/esm/lib/config.js +61 -33
  11. package/dist/esm/lib/constants.d.ts +89 -0
  12. package/dist/esm/lib/constants.d.ts.map +1 -0
  13. package/dist/esm/lib/constants.js +145 -0
  14. package/dist/esm/lib/drive/indexeddb-adapt.d.ts +12 -0
  15. package/dist/esm/lib/drive/indexeddb-adapt.d.ts.map +1 -1
  16. package/dist/esm/lib/drive/indexeddb-adapt.js +190 -20
  17. package/dist/esm/lib/drive/localstorage-adapt.d.ts +12 -0
  18. package/dist/esm/lib/drive/localstorage-adapt.d.ts.map +1 -1
  19. package/dist/esm/lib/drive/localstorage-adapt.js +179 -36
  20. package/dist/esm/lib/drive/memory-adapt.d.ts +10 -2
  21. package/dist/esm/lib/drive/memory-adapt.d.ts.map +1 -1
  22. package/dist/esm/lib/drive/memory-adapt.js +118 -26
  23. package/dist/esm/lib/drive/safe-storage.d.ts +24 -0
  24. package/dist/esm/lib/drive/safe-storage.d.ts.map +1 -0
  25. package/dist/esm/lib/drive/safe-storage.js +96 -0
  26. package/dist/esm/lib/drive/storage-interface.d.ts +20 -0
  27. package/dist/esm/lib/drive/storage-interface.d.ts.map +1 -1
  28. package/dist/esm/lib/error-trigger.d.ts +73 -0
  29. package/dist/esm/lib/error-trigger.d.ts.map +1 -0
  30. package/dist/esm/lib/error-trigger.js +162 -0
  31. package/dist/esm/lib/error.d.ts +9 -0
  32. package/dist/esm/lib/error.d.ts.map +1 -1
  33. package/dist/esm/lib/error.js +70 -118
  34. package/dist/esm/lib/init.d.ts +0 -4
  35. package/dist/esm/lib/init.d.ts.map +1 -1
  36. package/dist/esm/lib/init.js +148 -47
  37. package/dist/esm/lib/logger.d.ts +27 -0
  38. package/dist/esm/lib/logger.d.ts.map +1 -0
  39. package/dist/esm/lib/logger.js +79 -0
  40. package/dist/esm/lib/net.d.ts +11 -0
  41. package/dist/esm/lib/net.d.ts.map +1 -1
  42. package/dist/esm/lib/net.js +264 -119
  43. package/dist/esm/lib/request.d.ts.map +1 -1
  44. package/dist/esm/lib/request.js +2 -2
  45. package/dist/esm/lib/router-monitor.d.ts.map +1 -1
  46. package/dist/esm/lib/router-monitor.js +135 -49
  47. package/dist/esm/lib/rrweb.d.ts.map +1 -1
  48. package/dist/esm/lib/rrweb.js +31 -24
  49. package/dist/esm/lib/storage-manager.d.ts +12 -0
  50. package/dist/esm/lib/storage-manager.d.ts.map +1 -1
  51. package/dist/esm/lib/storage-manager.js +129 -46
  52. package/dist/esm/lib/upload-worker-manager.d.ts +47 -0
  53. package/dist/esm/lib/upload-worker-manager.d.ts.map +1 -0
  54. package/dist/esm/lib/upload-worker-manager.js +559 -0
  55. package/dist/esm/lib/upload-worker.d.ts +58 -0
  56. package/dist/esm/lib/upload-worker.d.ts.map +1 -0
  57. package/dist/esm/lib/upload-worker.js +28 -0
  58. package/dist/esm/lib/uploader.d.ts +43 -0
  59. package/dist/esm/lib/uploader.d.ts.map +1 -1
  60. package/dist/esm/lib/uploader.js +464 -102
  61. package/dist/esm/lib/utils.d.ts +75 -0
  62. package/dist/esm/lib/utils.d.ts.map +1 -1
  63. package/dist/esm/lib/utils.js +268 -5
  64. package/dist/lib/index.d.ts +14 -41
  65. package/dist/lib/index.d.ts.map +1 -1
  66. package/dist/lib/index.js +81 -63
  67. package/dist/lib/lib/api.d.ts +10 -0
  68. package/dist/lib/lib/api.d.ts.map +1 -1
  69. package/dist/lib/lib/api.js +59 -35
  70. package/dist/lib/lib/config.d.ts +13 -6
  71. package/dist/lib/lib/config.d.ts.map +1 -1
  72. package/dist/lib/lib/config.js +63 -33
  73. package/dist/lib/lib/constants.d.ts +89 -0
  74. package/dist/lib/lib/constants.d.ts.map +1 -0
  75. package/dist/lib/lib/constants.js +151 -0
  76. package/dist/lib/lib/drive/indexeddb-adapt.d.ts +12 -0
  77. package/dist/lib/lib/drive/indexeddb-adapt.d.ts.map +1 -1
  78. package/dist/lib/lib/drive/indexeddb-adapt.js +191 -19
  79. package/dist/lib/lib/drive/localstorage-adapt.d.ts +12 -0
  80. package/dist/lib/lib/drive/localstorage-adapt.d.ts.map +1 -1
  81. package/dist/lib/lib/drive/localstorage-adapt.js +179 -36
  82. package/dist/lib/lib/drive/memory-adapt.d.ts +10 -2
  83. package/dist/lib/lib/drive/memory-adapt.d.ts.map +1 -1
  84. package/dist/lib/lib/drive/memory-adapt.js +117 -26
  85. package/dist/lib/lib/drive/safe-storage.d.ts +24 -0
  86. package/dist/lib/lib/drive/safe-storage.d.ts.map +1 -0
  87. package/dist/lib/lib/drive/safe-storage.js +102 -0
  88. package/dist/lib/lib/drive/storage-interface.d.ts +20 -0
  89. package/dist/lib/lib/drive/storage-interface.d.ts.map +1 -1
  90. package/dist/lib/lib/error-trigger.d.ts +73 -0
  91. package/dist/lib/lib/error-trigger.d.ts.map +1 -0
  92. package/dist/lib/lib/error-trigger.js +167 -0
  93. package/dist/lib/lib/error.d.ts +9 -0
  94. package/dist/lib/lib/error.d.ts.map +1 -1
  95. package/dist/lib/lib/error.js +73 -118
  96. package/dist/lib/lib/init.d.ts +0 -4
  97. package/dist/lib/lib/init.d.ts.map +1 -1
  98. package/dist/lib/lib/init.js +144 -43
  99. package/dist/lib/lib/logger.d.ts +27 -0
  100. package/dist/lib/lib/logger.d.ts.map +1 -0
  101. package/dist/lib/lib/logger.js +84 -0
  102. package/dist/lib/lib/net.d.ts +11 -0
  103. package/dist/lib/lib/net.d.ts.map +1 -1
  104. package/dist/lib/lib/net.js +268 -120
  105. package/dist/lib/lib/request.d.ts.map +1 -1
  106. package/dist/lib/lib/request.js +3 -3
  107. package/dist/lib/lib/router-monitor.d.ts.map +1 -1
  108. package/dist/lib/lib/router-monitor.js +136 -49
  109. package/dist/lib/lib/rrweb.d.ts.map +1 -1
  110. package/dist/lib/lib/rrweb.js +31 -23
  111. package/dist/lib/lib/storage-manager.d.ts +12 -0
  112. package/dist/lib/lib/storage-manager.d.ts.map +1 -1
  113. package/dist/lib/lib/storage-manager.js +130 -46
  114. package/dist/lib/lib/upload-worker-manager.d.ts +47 -0
  115. package/dist/lib/lib/upload-worker-manager.d.ts.map +1 -0
  116. package/dist/lib/lib/upload-worker-manager.js +570 -0
  117. package/dist/lib/lib/upload-worker.d.ts +58 -0
  118. package/dist/lib/lib/upload-worker.d.ts.map +1 -0
  119. package/dist/lib/lib/upload-worker.js +33 -0
  120. package/dist/lib/lib/uploader.d.ts +43 -0
  121. package/dist/lib/lib/uploader.d.ts.map +1 -1
  122. package/dist/lib/lib/uploader.js +468 -101
  123. package/dist/lib/lib/utils.d.ts +75 -0
  124. package/dist/lib/lib/utils.d.ts.map +1 -1
  125. package/dist/lib/lib/utils.js +276 -6
  126. package/dist/rlog-sdk.min.js +1 -1
  127. package/package.json +3 -2
@@ -5,15 +5,23 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.getBlackListUrls = getBlackListUrls;
8
+ exports.getCustomHeaders = getCustomHeaders;
8
9
  exports.getSdkLogEndpoint = getSdkLogEndpoint;
9
10
  exports.getWhiteListUrls = getWhiteListUrls;
11
+ exports.normalizeUrl = normalizeUrl;
10
12
  exports.restoreXhr = restoreXhr;
11
13
  exports.setBlackListUrls = setBlackListUrls;
12
14
  exports.setCustomHeaders = setCustomHeaders;
15
+ exports.setNetErrorTrigger = setNetErrorTrigger;
13
16
  exports.setSdkLogEndpoint = setSdkLogEndpoint;
14
17
  exports.setWhiteListUrls = setWhiteListUrls;
15
18
  exports.shouldRecordUrl = shouldRecordUrl;
16
19
  exports.watchXhr = watchXhr;
20
+ var _rrweb = require("rrweb");
21
+ var _config = require("./config");
22
+ var _logger = _interopRequireDefault(require("./logger"));
23
+ var _constants = require("./constants");
24
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
25
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
18
26
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
19
27
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
@@ -28,9 +36,17 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
28
36
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
29
37
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
30
38
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
31
- // 根据业务需求配置的黑名单,监控和统计相关的接口
32
- var BLACK_HOST_NAME = ['arms', 'log', 'marmot-cloud.com', 'alipayobjects.com', 'renderpre.alipay.com', 'nemo-office.alipay.com', 'render.alipay.com'];
33
- var BLACK_PATH_NAME = ['r.png', 'dwcookieLogGet.do', 'track', 'spm', 'logstores', 'render', '.json', '.js', '.css', '.wasm', '.png', '.jpg', '.jpeg', '.weapp', '.data'];
39
+ // 错误触发器引用(错误采集模式下由 init.ts 注入)
40
+ var errorTriggerInstance = null;
41
+
42
+ /**
43
+ * 设置网络模块的错误触发器实例
44
+ */
45
+ function setNetErrorTrigger(trigger) {
46
+ errorTriggerInstance = trigger;
47
+ }
48
+
49
+ // 根据业务需求配置的黑名单和需要提取的响应头字段,已从 constants.ts 导入
34
50
 
35
51
  // 定义白名单URL列表和自定义请求头
36
52
  // 默认白名单为空,不抓取任何请求,需要用户手动配置
@@ -45,9 +61,6 @@ var blackListUrls = [
45
61
  // SDK日志上报接口地址
46
62
  var sdkLogEndpoint = null;
47
63
 
48
- // 需要提取的响应头字段
49
- var HEADERS_TO_EXTRACT = ['sky_trace_id', 'antbank-traceid'];
50
-
51
64
  // 辅助函数:规范化URL路径
52
65
  function normalizeUrl(url) {
53
66
  try {
@@ -98,9 +111,9 @@ function isUrlInBlacklist(url, blacklist) {
98
111
  var urlObj = new URL(normalizedUrl);
99
112
  var pathname = urlObj.pathname;
100
113
  var hostname = urlObj.hostname;
101
- if (BLACK_HOST_NAME.some(function (v) {
114
+ if (_constants.BLACK_HOST_NAME.some(function (v) {
102
115
  return hostname.includes(v);
103
- }) || BLACK_PATH_NAME.some(function (v) {
116
+ }) || _constants.BLACK_PATH_NAME.some(function (v) {
104
117
  return pathname.includes(v);
105
118
  })) {
106
119
  return true;
@@ -141,7 +154,7 @@ function isUrlInBlacklist(url, blacklist) {
141
154
  function shouldRecordUrl(url) {
142
155
  // 如果URL在黑名单中,直接返回false
143
156
  if (isUrlInBlacklist(url, blackListUrls)) {
144
- // console.log(`[Blacklist] ${url} - Skipped (in blacklist)`);
157
+ // logger.log(`[Blacklist] ${url} - Skipped (in blacklist)`);
145
158
 
146
159
  return false;
147
160
  }
@@ -155,6 +168,28 @@ function shouldRecordUrl(url) {
155
168
  return isUrlInWhitelist(url, whiteListUrls);
156
169
  }
157
170
 
171
+ // 网络状态变化事件处理
172
+ function handleOnline() {
173
+ try {
174
+ _rrweb.record.addCustomEvent(_constants.EVENT_NETWORK_STATUS, {
175
+ type: 'NETWORK_ONLINE',
176
+ timestamp: Date.now()
177
+ });
178
+ } catch (error) {
179
+ _logger.default.warn('Failed to add NETWORK_ONLINE event (recording may have stopped)', error);
180
+ }
181
+ }
182
+ function handleOffline() {
183
+ try {
184
+ _rrweb.record.addCustomEvent(_constants.EVENT_NETWORK_STATUS, {
185
+ type: 'NETWORK_OFFLINE',
186
+ timestamp: Date.now()
187
+ });
188
+ } catch (error) {
189
+ _logger.default.warn('Failed to add NETWORK_OFFLINE event (recording may have stopped)', error);
190
+ }
191
+ }
192
+
158
193
  // 存储原始方法
159
194
  var origOpen = XMLHttpRequest.prototype.open;
160
195
  var origSend = XMLHttpRequest.prototype.send;
@@ -164,167 +199,269 @@ var origFetch = window.fetch;
164
199
  var isHooked = false;
165
200
  function watchXhr(r) {
166
201
  if (isHooked) {
167
- console.warn('RLog Network monitoring is already active');
202
+ _logger.default.warn('Network monitoring is already active');
168
203
  return;
169
204
  }
170
- console.log('RLog Network monitoring is active');
171
205
  isHooked = true;
172
206
  // 拦截XMLHttpRequest
173
207
  XMLHttpRequest.prototype.open = function (method, url) {
174
208
  var async = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
175
209
  var username = arguments.length > 3 ? arguments[3] : undefined;
176
210
  var password = arguments.length > 4 ? arguments[4] : undefined;
177
- // 保存请求信息
178
- this._rlogRequest = {
179
- method: method,
180
- url: url.toString(),
181
- startTime: 0,
182
- endTime: 0
183
- };
211
+ try {
212
+ // 保存请求信息
213
+ this._rlogRequest = {
214
+ method: method,
215
+ url: url.toString(),
216
+ startTime: 0,
217
+ endTime: 0
218
+ };
219
+ } catch (error) {
220
+ _logger.default.warn('Failed to save XHR request info:', error);
221
+ }
184
222
 
185
- // 调用原始open方法
223
+ // 调用原始open方法(不能被 SDK 异常影响)
186
224
  return origOpen.apply(this, [method, url, async, username, password]);
187
225
  };
188
226
  XMLHttpRequest.prototype.send = function (body) {
189
227
  var _this = this;
190
- var requestInfo = this._rlogRequest;
191
- requestInfo.startTime = Date.now();
192
- var method = requestInfo.method; // 从请求信息中获取method
193
-
194
- // 仅对白名单中的URL添加自定义请求头,避免跨域请求因非标准头触发CORS preflight失败
195
- if (shouldRecordUrl(requestInfo.url)) {
196
- Object.entries(customHeaders).forEach(function (_ref) {
197
- var _ref2 = _slicedToArray(_ref, 2),
198
- key = _ref2[0],
199
- value = _ref2[1];
200
- _this.setRequestHeader(key, value);
201
- });
202
- }
228
+ try {
229
+ var requestInfo = this._rlogRequest;
230
+ if (requestInfo) {
231
+ requestInfo.startTime = Date.now();
203
232
 
204
- // 监听请求完成
205
- this.addEventListener('load', function () {
206
- var _this2 = this;
207
- requestInfo.endTime = Date.now();
208
- // 检查是否应该记录该URL
209
- if (shouldRecordUrl(requestInfo.url)) {
210
- // 提取指定响应头字段
211
- var responseHeaders = {};
212
- HEADERS_TO_EXTRACT.forEach(function (headerName) {
233
+ // 仅对白名单中的URL添加自定义请求头,避免跨域请求因非标准头触发CORS preflight失败
234
+ if (shouldRecordUrl(requestInfo.url)) {
213
235
  try {
214
- var value = _this2.getResponseHeader(headerName);
215
- if (value) {
216
- responseHeaders[headerName] = value;
236
+ Object.entries(customHeaders).forEach(function (_ref) {
237
+ var _ref2 = _slicedToArray(_ref, 2),
238
+ key = _ref2[0],
239
+ value = _ref2[1];
240
+ _this.setRequestHeader(key, value);
241
+ });
242
+ } catch (error) {
243
+ _logger.default.warn('Failed to set custom headers on XHR:', error);
244
+ }
245
+ }
246
+
247
+ // 监听请求完成
248
+ this.addEventListener('load', function () {
249
+ var _this2 = this;
250
+ try {
251
+ requestInfo.endTime = Date.now();
252
+ // 检查是否应该记录该URL
253
+ if (shouldRecordUrl(requestInfo.url)) {
254
+ // 提取指定响应头字段
255
+ var responseHeaders = {};
256
+ _constants.HEADERS_TO_EXTRACT.forEach(function (headerName) {
257
+ try {
258
+ var value = _this2.getResponseHeader(headerName);
259
+ if (value) {
260
+ responseHeaders[headerName] = value;
261
+ }
262
+ } catch (error) {
263
+ // 忽略无法访问的响应头(如CORS限制)
264
+ }
265
+ });
266
+ try {
267
+ r.addCustomEvent(_constants.EVENT_HTTP_SUCCESS, _objectSpread(_objectSpread({}, requestInfo), {}, {
268
+ dur: requestInfo.endTime - requestInfo.startTime,
269
+ responseHeaders: responseHeaders,
270
+ pagePath: window.location.href
271
+ }));
272
+ } catch (error) {
273
+ // 忽略录制已停止时的异常
274
+ }
275
+ }
276
+
277
+ // 错误采集模式下:检查 HTTP 状态码是否为错误
278
+ if (errorTriggerInstance) {
279
+ var _config$errorCapture$, _config$errorCapture;
280
+ var config = (0, _config.getConfig)();
281
+ var httpErrorThreshold = (_config$errorCapture$ = (_config$errorCapture = config.errorCapture) === null || _config$errorCapture === void 0 ? void 0 : _config$errorCapture.httpErrorThreshold) !== null && _config$errorCapture$ !== void 0 ? _config$errorCapture$ : 400;
282
+ if (this.status >= httpErrorThreshold) {
283
+ errorTriggerInstance.onError({
284
+ type: 'http',
285
+ message: "XHR ".concat(requestInfo.method, " ").concat(requestInfo.url, " responded with status ").concat(this.status),
286
+ timestamp: Date.now(),
287
+ detail: {
288
+ url: requestInfo.url,
289
+ method: requestInfo.method,
290
+ status: this.status
291
+ }
292
+ });
293
+ }
217
294
  }
218
295
  } catch (error) {
219
- // 忽略无法访问的响应头(如CORS限制)
220
- console.warn("\u65E0\u6CD5\u83B7\u53D6\u54CD\u5E94\u5934 ".concat(headerName, ":"), error);
296
+ _logger.default.warn('Error in XHR load handler:', error);
221
297
  }
222
298
  });
223
- try {
224
- r.addCustomEvent('http-success', _objectSpread(_objectSpread({}, requestInfo), {}, {
225
- dur: requestInfo.endTime - requestInfo.startTime,
226
- responseHeaders: responseHeaders,
227
- pagePath: window.location.href
228
- }));
229
- } catch (error) {
230
- // 忽略录制已停止时的异常
231
- console.warn('Failed to add custom event (recording may have stopped):', error);
232
- }
233
- }
234
- });
235
299
 
236
- // 监听请求错误
237
- this.addEventListener('error', function () {
238
- try {
239
- r.addCustomEvent('http-error', _objectSpread(_objectSpread({}, requestInfo), {}, {
240
- dur: requestInfo.endTime - requestInfo.startTime,
241
- pagePath: window.location.href
242
- }));
243
- } catch (error) {
244
- // 忽略录制已停止时的异常
245
- console.warn('Failed to add custom event (recording may have stopped):', error);
300
+ // 监听请求错误
301
+ this.addEventListener('error', function () {
302
+ try {
303
+ r.addCustomEvent(_constants.EVENT_HTTP_ERROR, _objectSpread(_objectSpread({}, requestInfo), {}, {
304
+ dur: requestInfo.endTime - requestInfo.startTime,
305
+ pagePath: window.location.href
306
+ }));
307
+ } catch (error) {
308
+ // 忽略录制已停止时的异常
309
+ }
310
+
311
+ // 错误采集模式下:XHR 网络错误触发
312
+ try {
313
+ if (errorTriggerInstance) {
314
+ errorTriggerInstance.onError({
315
+ type: 'http',
316
+ message: "XHR ".concat(requestInfo.method, " ").concat(requestInfo.url, " network error"),
317
+ timestamp: Date.now(),
318
+ detail: {
319
+ url: requestInfo.url,
320
+ method: requestInfo.method
321
+ }
322
+ });
323
+ }
324
+ } catch (error) {
325
+ _logger.default.warn('Error in XHR error trigger:', error);
326
+ }
327
+ });
246
328
  }
247
- });
329
+ } catch (error) {
330
+ _logger.default.warn('Error in XHR send hook:', error);
331
+ }
248
332
 
249
- // 调用原始send方法
333
+ // 调用原始send方法(不能被 SDK 异常影响)
250
334
  return origSend.apply(this, [body]);
251
335
  };
252
336
 
253
337
  // 拦截fetch API
254
338
  window.fetch = /*#__PURE__*/function () {
255
339
  var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(input, init) {
256
- var url, method, startTime, newInit, response, endTime, responseHeaders;
340
+ var url, method, startTime, actualInit, response, endTime, responseHeaders, _config$errorCapture$2, _config$errorCapture2, config, httpErrorThreshold;
257
341
  return _regeneratorRuntime().wrap(function _callee$(_context) {
258
342
  while (1) switch (_context.prev = _context.next) {
259
343
  case 0:
344
+ _context.prev = 0;
260
345
  url = input instanceof Request ? input.url : input.toString();
261
- method = (init === null || init === void 0 ? void 0 : init.method) || (input instanceof Request ? input.method : 'GET').toUpperCase(); // 统一转大写
262
- startTime = Date.now();
263
- _context.prev = 3;
264
- newInit = _objectSpread({}, init); // 仅对白名单中的URL添加自定义请求头,避免跨域请求因非标准头触发CORS preflight失败
265
- if (shouldRecordUrl(url) && Object.keys(customHeaders).length > 0) {
266
- newInit.headers = _objectSpread(_objectSpread({}, (init === null || init === void 0 ? void 0 : init.headers) || {}), customHeaders);
267
- }
346
+ method = (init === null || init === void 0 ? void 0 : init.method) || (input instanceof Request ? input.method : 'GET').toUpperCase();
268
347
  _context.next = 8;
269
- return origFetch(input, newInit);
348
+ break;
349
+ case 5:
350
+ _context.prev = 5;
351
+ _context.t0 = _context["catch"](0);
352
+ return _context.abrupt("return", origFetch(input, init));
270
353
  case 8:
271
- response = _context.sent;
272
- endTime = Date.now(); // 检查是否应该记录该URL
273
- if (shouldRecordUrl(url)) {
274
- console.log("[Fetch] ".concat(method, " ").concat(url, " - ").concat(endTime - startTime, "ms"));
275
-
276
- // 提取指定响应头字段
277
- responseHeaders = {};
278
- HEADERS_TO_EXTRACT.forEach(function (headerName) {
279
- try {
280
- var value = response.headers.get(headerName);
281
- if (value) {
282
- responseHeaders[headerName] = value;
283
- }
284
- } catch (error) {
285
- // 忽略无法访问的响应头(如CORS限制)
286
- console.warn("\u65E0\u6CD5\u83B7\u53D6\u54CD\u5E94\u5934 ".concat(headerName, ":"), error);
287
- }
288
- });
289
- try {
290
- r.addCustomEvent('http-success', {
291
- url: url,
292
- method: method,
293
- dur: endTime - startTime,
294
- responseHeaders: responseHeaders,
295
- pagePath: window.location.href
354
+ startTime = Date.now(); // 构建请求参数,仅对白名单 URL 添加自定义头
355
+ actualInit = init;
356
+ try {
357
+ if (shouldRecordUrl(url) && Object.keys(customHeaders).length > 0) {
358
+ actualInit = _objectSpread(_objectSpread({}, init), {}, {
359
+ headers: _objectSpread(_objectSpread({}, (init === null || init === void 0 ? void 0 : init.headers) || {}), customHeaders)
296
360
  });
297
- } catch (error) {
298
- // 忽略录制已停止时的异常
299
- console.warn('Failed to add custom event (recording may have stopped):', error);
300
361
  }
362
+ } catch (error) {
363
+ _logger.default.warn('Failed to add custom headers on Fetch:', error);
364
+ actualInit = init;
301
365
  }
302
- return _context.abrupt("return", response);
366
+ _context.prev = 11;
367
+ _context.next = 14;
368
+ return origFetch(input, actualInit);
303
369
  case 14:
304
- _context.prev = 14;
305
- _context.t0 = _context["catch"](3);
306
- console.error("[Fetch Error] ".concat(method, " ").concat(url), _context.t0);
370
+ response = _context.sent;
371
+ _context.next = 22;
372
+ break;
373
+ case 17:
374
+ _context.prev = 17;
375
+ _context.t1 = _context["catch"](11);
376
+ // Fetch 网络错误:先做 SDK 记录,再原样抛出给业务
307
377
  try {
308
- r.addCustomEvent('http-error', {
378
+ r.addCustomEvent(_constants.EVENT_HTTP_ERROR, {
309
379
  url: url,
310
380
  method: method,
311
381
  pagePath: window.location.href
312
382
  });
313
- } catch (eventError) {
314
- // 忽略录制已停止时的异常
315
- console.warn('Failed to add custom event (recording may have stopped):', eventError);
383
+ } catch (_) {
384
+ // 忽略录制异常
316
385
  }
317
- throw _context.t0;
318
- case 19:
386
+ try {
387
+ if (errorTriggerInstance) {
388
+ errorTriggerInstance.onError({
389
+ type: 'http',
390
+ message: "Fetch ".concat(method, " ").concat(url, " network error"),
391
+ timestamp: Date.now(),
392
+ detail: {
393
+ url: url,
394
+ method: method,
395
+ error: String(_context.t1)
396
+ }
397
+ });
398
+ }
399
+ } catch (_) {
400
+ // 忽略错误触发器异常
401
+ }
402
+ throw _context.t1;
403
+ case 22:
404
+ // 请求成功后的 SDK 记录逻辑,全部 try/catch 保护
405
+ try {
406
+ endTime = Date.now();
407
+ if (shouldRecordUrl(url)) {
408
+ responseHeaders = {};
409
+ _constants.HEADERS_TO_EXTRACT.forEach(function (headerName) {
410
+ try {
411
+ var value = response.headers.get(headerName);
412
+ if (value) {
413
+ responseHeaders[headerName] = value;
414
+ }
415
+ } catch (_) {
416
+ // 忽略无法访问的响应头
417
+ }
418
+ });
419
+ try {
420
+ r.addCustomEvent(_constants.EVENT_HTTP_SUCCESS, {
421
+ url: url,
422
+ method: method,
423
+ dur: endTime - startTime,
424
+ responseHeaders: responseHeaders,
425
+ pagePath: window.location.href
426
+ });
427
+ } catch (_) {
428
+ // 忽略录制异常
429
+ }
430
+ }
431
+ if (errorTriggerInstance) {
432
+ config = (0, _config.getConfig)();
433
+ httpErrorThreshold = (_config$errorCapture$2 = (_config$errorCapture2 = config.errorCapture) === null || _config$errorCapture2 === void 0 ? void 0 : _config$errorCapture2.httpErrorThreshold) !== null && _config$errorCapture$2 !== void 0 ? _config$errorCapture$2 : 400;
434
+ if (response.status >= httpErrorThreshold) {
435
+ errorTriggerInstance.onError({
436
+ type: 'http',
437
+ message: "Fetch ".concat(method, " ").concat(url, " responded with status ").concat(response.status),
438
+ timestamp: Date.now(),
439
+ detail: {
440
+ url: url,
441
+ method: method,
442
+ status: response.status
443
+ }
444
+ });
445
+ }
446
+ }
447
+ } catch (error) {
448
+ _logger.default.warn('Error in Fetch success handler:', error);
449
+ }
450
+ return _context.abrupt("return", response);
451
+ case 24:
319
452
  case "end":
320
453
  return _context.stop();
321
454
  }
322
- }, _callee, null, [[3, 14]]);
455
+ }, _callee, null, [[0, 5], [11, 17]]);
323
456
  }));
324
457
  return function (_x, _x2) {
325
458
  return _ref3.apply(this, arguments);
326
459
  };
327
460
  }();
461
+
462
+ // 监听网络连接状态变化
463
+ window.addEventListener('online', handleOnline);
464
+ window.addEventListener('offline', handleOffline);
328
465
  }
329
466
 
330
467
  // 恢复原始方法
@@ -338,8 +475,11 @@ function restoreXhr() {
338
475
  if (origFetch) {
339
476
  window.fetch = origFetch;
340
477
  }
478
+
479
+ // 移除网络状态监听器
480
+ window.removeEventListener('online', handleOnline);
481
+ window.removeEventListener('offline', handleOffline);
341
482
  isHooked = false;
342
- console.log('RLog network monitoring restored');
343
483
  }
344
484
 
345
485
  // 导出配置方法
@@ -386,7 +526,7 @@ function setSdkLogEndpoint(endpoint) {
386
526
  sdkLogEndpoint = endpoint;
387
527
 
388
528
  // 规范化endpoint路径,确保相对路径也能正确匹配
389
- var normalizedEndpoint = endpoint.startsWith('/') ? endpoint : '/' + endpoint;
529
+ var normalizedEndpoint = normalizeUrl(endpoint);
390
530
 
391
531
  // 自动将SDK日志上报接口加入黑名单,避免循环上报
392
532
  // 同时添加原始路径和规范化路径,确保兼容性
@@ -416,4 +556,12 @@ function getSdkLogEndpoint() {
416
556
  */
417
557
  function setCustomHeaders(headers) {
418
558
  Object.assign(customHeaders, headers);
559
+ }
560
+
561
+ /**
562
+ * 获取当前设置的自定义请求头
563
+ * @returns 当前自定义请求头的副本
564
+ */
565
+ function getCustomHeaders() {
566
+ return _objectSpread({}, customHeaders);
419
567
  }
@@ -1 +1 @@
1
- {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../../src/lib/request.ts"],"names":[],"mappings":"AACA,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,GAAG,CAAC;IACV,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC;IACrB,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CACzB;AAED;;;;;GAKG;AACH,wBAAsB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAwE1F;AAED;;;;;GAKG;AACH,wBAAsB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,IAAI,CAAC,cAAc,EAAE,QAAQ,GAAG,MAAM,CAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAE/G;AAED;;;;;;GAMG;AACH,wBAAsB,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,OAAO,GAAE,IAAI,CAAC,cAAc,EAAE,QAAQ,CAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAEnH"}
1
+ {"version":3,"file":"request.d.ts","sourceRoot":"","sources":["../../../src/lib/request.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,cAAc;IAC7B,MAAM,CAAC,EAAE,KAAK,GAAG,MAAM,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IACjC,IAAI,CAAC,EAAE,GAAG,CAAC;IACX,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,QAAQ;IACvB,EAAE,EAAE,OAAO,CAAC;IACZ,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,MAAM,CAAC;IACnB,IAAI,EAAE,GAAG,CAAC;IACV,IAAI,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC;IACrB,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC,CAAC;CACzB;AAED;;;;;GAKG;AACH,wBAAsB,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,cAAmB,GAAG,OAAO,CAAC,QAAQ,CAAC,CAwE1F;AAED;;;;;GAKG;AACH,wBAAsB,GAAG,CAAC,GAAG,EAAE,MAAM,EAAE,OAAO,GAAE,IAAI,CAAC,cAAc,EAAE,QAAQ,GAAG,MAAM,CAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAE/G;AAED;;;;;;GAMG;AACH,wBAAsB,IAAI,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,GAAG,EAAE,OAAO,GAAE,IAAI,CAAC,cAAc,EAAE,QAAQ,CAAM,GAAG,OAAO,CAAC,QAAQ,CAAC,CAEnH"}
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.get = get;
7
7
  exports.post = post;
8
8
  exports.request = request;
9
+ var _constants = require("./constants");
9
10
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
10
11
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
11
12
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
@@ -14,8 +15,7 @@ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e
14
15
  function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
15
16
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
16
17
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
17
- function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
18
- // 简单的 XMLHttpRequest 封装,提供更好的兼容性
18
+ function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } // 简单的 XMLHttpRequest 封装,提供更好的兼容性
19
19
  /**
20
20
  * 发送 HTTP 请求
21
21
  * @param url 请求地址
@@ -46,7 +46,7 @@ function _request() {
46
46
  headers = _options$headers === void 0 ? {} : _options$headers,
47
47
  body = options.body,
48
48
  _options$timeout = options.timeout,
49
- timeout = _options$timeout === void 0 ? 10000 : _options$timeout;
49
+ timeout = _options$timeout === void 0 ? _constants.REQUEST_TIMEOUT : _options$timeout;
50
50
  var xhr = new XMLHttpRequest();
51
51
 
52
52
  // 设置超时
@@ -1 +1 @@
1
- {"version":3,"file":"router-monitor.d.ts","sourceRoot":"","sources":["../../../src/lib/router-monitor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,KAAK,SAAS,EAAa,MAAM,UAAU,CAAC;AAGrD,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,cAAc,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,WAAW,GAAG,cAAc,GAAG,UAAU,GAAG,YAAY,CAAC;IACjE,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AA2JD;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,SAAS,CAAC,eAAe,CAAC,GAAG,IAAI,CAwB3E;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC,eAAe,CAAC,QAmCpE;AAED;;GAEG;AACH,wBAAgB,mBAAmB;;;;EAMlC;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,QAG1D;AAED;;GAEG;AACH,wBAAgB,iBAAiB,SAyBhC"}
1
+ {"version":3,"file":"router-monitor.d.ts","sourceRoot":"","sources":["../../../src/lib/router-monitor.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,EAAE,KAAK,SAAS,EAAa,MAAM,UAAU,CAAC;AAKrD,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,cAAc,CAAC;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,EAAE,WAAW,GAAG,cAAc,GAAG,UAAU,GAAG,YAAY,CAAC;IACjE,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAoJD;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,SAAS,CAAC,eAAe,CAAC,GAAG,IAAI,CAuB3E;AAuFD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,CAAC,EAAE,SAAS,CAAC,eAAe,CAAC,QA0CpE;AAED;;GAEG;AACH,wBAAgB,mBAAmB;;;;EAMlC;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,MAAM,QAG1D;AAED;;GAEG;AACH,wBAAgB,iBAAiB,SA4BhC"}