web-tracing-core 2.1.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 (61) hide show
  1. package/__test__/css/performance.css +3 -0
  2. package/__test__/err-batch.spec.ts +47 -0
  3. package/__test__/err.spec.ts +82 -0
  4. package/__test__/event.spec.ts +62 -0
  5. package/__test__/html/performance.html +57 -0
  6. package/__test__/html/recordscreen.html +39 -0
  7. package/__test__/http.spec.ts +143 -0
  8. package/__test__/img/performance.png +0 -0
  9. package/__test__/js/performance.js +3 -0
  10. package/__test__/performance.spec.ts +112 -0
  11. package/__test__/recordscreen.spec.ts +50 -0
  12. package/__test__/utils/index.ts +99 -0
  13. package/__test__/utils/pollify.ts +14 -0
  14. package/__test__/utils.spec.ts +18 -0
  15. package/dist/LICENSE +21 -0
  16. package/dist/README.md +97 -0
  17. package/dist/index.cjs +15943 -0
  18. package/dist/index.d.ts +323 -0
  19. package/dist/index.iife.js +15946 -0
  20. package/dist/index.iife.min.js +28 -0
  21. package/dist/index.mjs +15913 -0
  22. package/dist/package.json +49 -0
  23. package/index.ts +75 -0
  24. package/package.json +49 -0
  25. package/src/common/config.ts +13 -0
  26. package/src/common/constant.ts +57 -0
  27. package/src/common/index.ts +2 -0
  28. package/src/lib/base.ts +129 -0
  29. package/src/lib/err-batch.ts +134 -0
  30. package/src/lib/err.ts +323 -0
  31. package/src/lib/event-dwell.ts +63 -0
  32. package/src/lib/event.ts +252 -0
  33. package/src/lib/eventBus.ts +97 -0
  34. package/src/lib/exportMethods.ts +208 -0
  35. package/src/lib/http.ts +197 -0
  36. package/src/lib/intersectionObserver.ts +164 -0
  37. package/src/lib/line-status.ts +45 -0
  38. package/src/lib/options.ts +325 -0
  39. package/src/lib/performance.ts +302 -0
  40. package/src/lib/pv.ts +199 -0
  41. package/src/lib/recordscreen.ts +169 -0
  42. package/src/lib/replace.ts +371 -0
  43. package/src/lib/sendData.ts +264 -0
  44. package/src/observer/computed.ts +52 -0
  45. package/src/observer/config.ts +1 -0
  46. package/src/observer/dep.ts +21 -0
  47. package/src/observer/index.ts +91 -0
  48. package/src/observer/ref.ts +80 -0
  49. package/src/observer/types.ts +22 -0
  50. package/src/observer/watch.ts +19 -0
  51. package/src/observer/watcher.ts +88 -0
  52. package/src/types/index.ts +126 -0
  53. package/src/utils/debug.ts +17 -0
  54. package/src/utils/element.ts +47 -0
  55. package/src/utils/fingerprintjs.ts +2132 -0
  56. package/src/utils/getIps.ts +127 -0
  57. package/src/utils/global.ts +49 -0
  58. package/src/utils/index.ts +551 -0
  59. package/src/utils/is.ts +78 -0
  60. package/src/utils/localStorage.ts +70 -0
  61. package/src/utils/session.ts +27 -0
@@ -0,0 +1,127 @@
1
+ // @ts-nocheck
2
+ /**
3
+ * 获取ip
4
+ * 注:此文件为 webrtc-ip[https://github.com/joeymalvinni/webrtc-ip] v3.0.1 离线版本
5
+ */
6
+ function is_ipv4(d) {
7
+ return regex_v4.test(d)
8
+ }
9
+ function is_ipv6(d) {
10
+ return regex_v6.test(d)
11
+ }
12
+ const simpleIPRegex =
13
+ /([0-9]{1,3}(\.[0-9]{1,3}){3}|[a-f0-9]{1,4}(:[a-f0-9]{1,4}){7})/g
14
+ const regex_v4 =
15
+ /((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])/,
16
+ regex_v6 =
17
+ /((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))/,
18
+ ip_regex_array = [regex_v6, regex_v4]
19
+ function peer(d) {
20
+ let e,
21
+ t =
22
+ window.RTCPeerConnection ||
23
+ window.mozRTCPeerConnection ||
24
+ window.webkitRTCPeerConnection
25
+ function n() {
26
+ ;((e = new t({
27
+ iceServers: [{ urls: 'stun:stun.l.google.com:19302' }]
28
+ })).onicecandidate = d => f(d)),
29
+ e.createDataChannel('fake_data_channel')
30
+ }
31
+ function a() {
32
+ return e.createOffer().then(d => e.setLocalDescription(d))
33
+ }
34
+ function f(e) {
35
+ e &&
36
+ e.candidate &&
37
+ e.candidate.candidate &&
38
+ d(e && e.candidate && e.candidate.candidate)
39
+ }
40
+ return {
41
+ start: function () {
42
+ n(), a()
43
+ },
44
+ stop: function () {
45
+ if (e)
46
+ try {
47
+ e.close()
48
+ } finally {
49
+ ;(e.onicecandidate = () => {}), (e = null)
50
+ }
51
+ },
52
+ createConnection: n,
53
+ createStunRequest: a,
54
+ handleCandidates: f
55
+ }
56
+ }
57
+ function publicIPs(d) {
58
+ if (d && d < 100)
59
+ throw new Error('Custom timeout cannot be under 100 milliseconds.')
60
+ const e = [],
61
+ t = peer(function (d) {
62
+ const t = []
63
+ for (const e of ip_regex_array) {
64
+ const n = [],
65
+ a = e.exec(d)
66
+ if (a) {
67
+ for (let d = 0; d < a.length; d++)
68
+ (is_ipv4(a[d]) || is_ipv6(a[d])) && n.push(a[d])
69
+ t.push(n)
70
+ }
71
+ }
72
+ !(function (d) {
73
+ e.includes(d) || e.push(n(d.flat(1 / 0)))
74
+ })(t.flat(1 / 0))
75
+ })
76
+ function n(d) {
77
+ return Array.from(new Set(d))
78
+ }
79
+ return new Promise(function (a, f) {
80
+ t.start(),
81
+ setTimeout(() => {
82
+ e && e !== [] ? a(n(e.flat(1 / 0))) : f('No IP addresses were found.'),
83
+ t.stop()
84
+ }, d || 500)
85
+ })
86
+ }
87
+ function getIPTypes(d) {
88
+ return new Promise(function (e, t) {
89
+ const n = []
90
+ publicIPs(d)
91
+ .then(d => {
92
+ d.forEach(d => {
93
+ d.match(/^(192\.168\.|169\.254\.|10\.|172\.(1[6-9]|2\d|3[01]))/)
94
+ ? n.push({ ip: d, type: 'private', IPv4: !0 })
95
+ : d.match(
96
+ /((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:)))/
97
+ )
98
+ ? n.push({ ip: d, type: 'IPv6', IPv4: !1 })
99
+ : n.push({ ip: d, type: 'public', IPv4: !0 })
100
+ }),
101
+ e(n)
102
+ })
103
+ .catch(t)
104
+ })
105
+ }
106
+ function getIPv4(d) {
107
+ return getIPTypes(d).then(d => {
108
+ const e = d.filter(d => d.IPv4)
109
+ for (let d = 0; d < e.length; d++) e[d] = e[d].ip
110
+ return e || ''
111
+ })
112
+ }
113
+ function getIPv6(d) {
114
+ return getIPTypes(d).then(d => {
115
+ const e = d.filter(d => 'IPv6' === d.type)
116
+ for (let d = 0; d < e.length; d++) e[d] = e[d].ip
117
+ return e ? e.ip : ''
118
+ })
119
+ }
120
+ export function getIPs(d?: any) {
121
+ return Object.assign(publicIPs(d), {
122
+ types: getIPTypes,
123
+ public: publicIPs,
124
+ IPv4: getIPv4,
125
+ IPv6: getIPv6
126
+ })
127
+ }
@@ -0,0 +1,49 @@
1
+ import { isWindow } from './is'
2
+ import { WebTracing } from '../types'
3
+
4
+ /**
5
+ * 是否为浏览器环境
6
+ */
7
+ export const isBrowserEnv = isWindow(typeof window !== 'undefined' ? window : 0)
8
+
9
+ /**
10
+ * 是否为 electron 环境
11
+ */
12
+ export const isElectronEnv = !!window?.process?.versions?.electron
13
+
14
+ /**
15
+ * 是否为测试环境
16
+ */
17
+ export const isTestEnv =
18
+ (typeof navigator !== 'undefined' && navigator.userAgent.includes('jsdom')) ||
19
+ // @ts-expect-error: jsdom
20
+ (typeof window !== 'undefined' && window.jsdom)
21
+
22
+ /**
23
+ * 获取全局变量
24
+ */
25
+ export function getGlobal(): Window {
26
+ if (isBrowserEnv || isElectronEnv || isTestEnv) return window
27
+ return {} as Window
28
+ }
29
+
30
+ /**
31
+ * 获取全部变量 __webTracing__ 的引用地址
32
+ */
33
+ export function getGlobalSupport(): WebTracing {
34
+ _global.__webTracing__ = _global.__webTracing__ || ({} as WebTracing)
35
+ return _global.__webTracing__
36
+ }
37
+
38
+ /**
39
+ * 判断sdk是否初始化
40
+ * @returns sdk是否初始化
41
+ */
42
+ export function isInit(): boolean {
43
+ return !!_global.__webTracingInit__
44
+ }
45
+
46
+ const _global = getGlobal()
47
+ const _support = getGlobalSupport()
48
+
49
+ export { _global, _support }