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.
- package/__test__/css/performance.css +3 -0
- package/__test__/err-batch.spec.ts +47 -0
- package/__test__/err.spec.ts +82 -0
- package/__test__/event.spec.ts +62 -0
- package/__test__/html/performance.html +57 -0
- package/__test__/html/recordscreen.html +39 -0
- package/__test__/http.spec.ts +143 -0
- package/__test__/img/performance.png +0 -0
- package/__test__/js/performance.js +3 -0
- package/__test__/performance.spec.ts +112 -0
- package/__test__/recordscreen.spec.ts +50 -0
- package/__test__/utils/index.ts +99 -0
- package/__test__/utils/pollify.ts +14 -0
- package/__test__/utils.spec.ts +18 -0
- package/dist/LICENSE +21 -0
- package/dist/README.md +97 -0
- package/dist/index.cjs +15943 -0
- package/dist/index.d.ts +323 -0
- package/dist/index.iife.js +15946 -0
- package/dist/index.iife.min.js +28 -0
- package/dist/index.mjs +15913 -0
- package/dist/package.json +49 -0
- package/index.ts +75 -0
- package/package.json +49 -0
- package/src/common/config.ts +13 -0
- package/src/common/constant.ts +57 -0
- package/src/common/index.ts +2 -0
- package/src/lib/base.ts +129 -0
- package/src/lib/err-batch.ts +134 -0
- package/src/lib/err.ts +323 -0
- package/src/lib/event-dwell.ts +63 -0
- package/src/lib/event.ts +252 -0
- package/src/lib/eventBus.ts +97 -0
- package/src/lib/exportMethods.ts +208 -0
- package/src/lib/http.ts +197 -0
- package/src/lib/intersectionObserver.ts +164 -0
- package/src/lib/line-status.ts +45 -0
- package/src/lib/options.ts +325 -0
- package/src/lib/performance.ts +302 -0
- package/src/lib/pv.ts +199 -0
- package/src/lib/recordscreen.ts +169 -0
- package/src/lib/replace.ts +371 -0
- package/src/lib/sendData.ts +264 -0
- package/src/observer/computed.ts +52 -0
- package/src/observer/config.ts +1 -0
- package/src/observer/dep.ts +21 -0
- package/src/observer/index.ts +91 -0
- package/src/observer/ref.ts +80 -0
- package/src/observer/types.ts +22 -0
- package/src/observer/watch.ts +19 -0
- package/src/observer/watcher.ts +88 -0
- package/src/types/index.ts +126 -0
- package/src/utils/debug.ts +17 -0
- package/src/utils/element.ts +47 -0
- package/src/utils/fingerprintjs.ts +2132 -0
- package/src/utils/getIps.ts +127 -0
- package/src/utils/global.ts +49 -0
- package/src/utils/index.ts +551 -0
- package/src/utils/is.ts +78 -0
- package/src/utils/localStorage.ts +70 -0
- package/src/utils/session.ts +27 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import path from 'path'
|
|
2
|
+
import http from 'http'
|
|
3
|
+
import url from 'url'
|
|
4
|
+
import fs from 'fs'
|
|
5
|
+
import puppeteer from 'puppeteer'
|
|
6
|
+
|
|
7
|
+
interface IMimeType {
|
|
8
|
+
[key: string]: string
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export function startServer(defaultPort = 3030) {
|
|
12
|
+
return new Promise<http.Server>((resolve, reject) => {
|
|
13
|
+
const mimeType: IMimeType = {
|
|
14
|
+
'.html': 'text/html',
|
|
15
|
+
'.js': 'text/javascript',
|
|
16
|
+
'.css': 'text/css',
|
|
17
|
+
'.png': 'image/png'
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const s = http.createServer((req, res) => {
|
|
21
|
+
const parsedUrl = url.parse(req.url!)
|
|
22
|
+
const sanitizePath = path
|
|
23
|
+
.normalize(parsedUrl.pathname!)
|
|
24
|
+
.replace(/^(\.\.[/\\])+/, '')
|
|
25
|
+
const pathname = path.join(__dirname, '../', sanitizePath)
|
|
26
|
+
|
|
27
|
+
try {
|
|
28
|
+
const data = fs.readFileSync(pathname)
|
|
29
|
+
const ext = path.parse(pathname).ext
|
|
30
|
+
res.setHeader('Content-type', mimeType[ext] || 'text/plain')
|
|
31
|
+
res.setHeader('Access-Control-Allow-Origin', '*')
|
|
32
|
+
res.setHeader('Access-Control-Allow-Methods', 'GET')
|
|
33
|
+
res.setHeader('Access-Control-Allow-Headers', 'Content-type')
|
|
34
|
+
setTimeout(() => {
|
|
35
|
+
res.end(data)
|
|
36
|
+
}, 100)
|
|
37
|
+
} catch (error) {
|
|
38
|
+
res.end()
|
|
39
|
+
}
|
|
40
|
+
})
|
|
41
|
+
s.listen(defaultPort)
|
|
42
|
+
.on('listening', () => {
|
|
43
|
+
resolve(s)
|
|
44
|
+
})
|
|
45
|
+
.on('error', e => {
|
|
46
|
+
reject(e)
|
|
47
|
+
})
|
|
48
|
+
})
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function getServerURL(server: http.Server): string {
|
|
52
|
+
const address = server.address()
|
|
53
|
+
if (address && typeof address !== 'string') {
|
|
54
|
+
return `http://localhost:${address.port}`
|
|
55
|
+
} else {
|
|
56
|
+
return `${address}`
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export function replaceLast(str: string, find: string, replace: string) {
|
|
61
|
+
const index = str.lastIndexOf(find)
|
|
62
|
+
if (index === -1) {
|
|
63
|
+
return str
|
|
64
|
+
}
|
|
65
|
+
return str.substring(0, index) + replace + str.substring(index + find.length)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
export async function launchPuppeteer(
|
|
69
|
+
options?: Parameters<(typeof puppeteer)['launch']>[0]
|
|
70
|
+
) {
|
|
71
|
+
return await puppeteer.launch({
|
|
72
|
+
headless: true,
|
|
73
|
+
defaultViewport: {
|
|
74
|
+
width: 1920,
|
|
75
|
+
height: 1080
|
|
76
|
+
},
|
|
77
|
+
args: ['--no-sandbox'],
|
|
78
|
+
...options
|
|
79
|
+
})
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function getHtml(fileName: string, code: string) {
|
|
83
|
+
const filePath = path.resolve(__dirname, `../html/${fileName}`)
|
|
84
|
+
const html = fs.readFileSync(filePath, 'utf8')
|
|
85
|
+
return replaceLast(
|
|
86
|
+
html,
|
|
87
|
+
'</body>',
|
|
88
|
+
`
|
|
89
|
+
<script>
|
|
90
|
+
${code}
|
|
91
|
+
</script>
|
|
92
|
+
</body>
|
|
93
|
+
`
|
|
94
|
+
)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export function delay(timeout: number) {
|
|
98
|
+
return new Promise(resolve => setTimeout(resolve, timeout))
|
|
99
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export type PromiseRejectionEventInit = {
|
|
2
|
+
promise: Promise<any>
|
|
3
|
+
reason: any
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
export class PromiseRejectionEvent extends Event {
|
|
7
|
+
public readonly reason: any
|
|
8
|
+
public readonly promise: Promise<any>
|
|
9
|
+
constructor(type: string, eventInitDict: PromiseRejectionEventInit) {
|
|
10
|
+
super(type)
|
|
11
|
+
this.promise = eventInitDict.promise
|
|
12
|
+
this.reason = eventInitDict.reason
|
|
13
|
+
}
|
|
14
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { getNodeXPath } from '../src/utils/element'
|
|
2
|
+
|
|
3
|
+
describe('utils', () => {
|
|
4
|
+
it('getNodeXPath should work', () => {
|
|
5
|
+
const element = document.createElement('div')
|
|
6
|
+
element.innerHTML = `
|
|
7
|
+
<div id="wrapper">
|
|
8
|
+
<div></div>
|
|
9
|
+
<div></div>
|
|
10
|
+
<div>
|
|
11
|
+
<div class="target"></div>
|
|
12
|
+
</div>
|
|
13
|
+
</div>
|
|
14
|
+
`
|
|
15
|
+
const target = element.querySelector('.target')!
|
|
16
|
+
expect(getNodeXPath(target)).toBe('#wrapper>div>div')
|
|
17
|
+
})
|
|
18
|
+
})
|
package/dist/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2022 M-cheng-web
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/README.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
<img src="https://github.com/M-cheng-web/image-provider/raw/main/web-tracing/logo.7k1jidnhjr40.svg" width="128" alt="logo" />
|
|
3
|
+
<h1>web-tracing 监控插件</h1>
|
|
4
|
+
<p>
|
|
5
|
+
基于 JS 跨平台插件,为前端项目提供【 埋点、行为、性能、异常、请求、资源、路由、曝光、录屏 】监控手段
|
|
6
|
+
</p>
|
|
7
|
+
</div>
|
|
8
|
+
|
|
9
|
+
## 官方文档
|
|
10
|
+
[官方文档 https://m-cheng-web.github.io/web-tracing/](https://m-cheng-web.github.io/web-tracing/)
|
|
11
|
+
|
|
12
|
+
## DeepWiki文档
|
|
13
|
+
[DeepWiki文档 https://deepwiki.com/M-cheng-web/web-tracing](https://deepwiki.com/M-cheng-web/web-tracing)
|
|
14
|
+
|
|
15
|
+
## 示例项目(本地)
|
|
16
|
+
[js版本 https://github.com/M-cheng-web/web-tracing-examples-js](https://github.com/M-cheng-web/web-tracing-examples-js)
|
|
17
|
+
|
|
18
|
+
[vue2版本 https://github.com/M-cheng-web/web-tracing-examples-vue2](https://github.com/M-cheng-web/web-tracing-examples-vue2)
|
|
19
|
+
|
|
20
|
+
[vue3版本 https://github.com/M-cheng-web/web-tracing-examples-vue3](https://github.com/M-cheng-web/web-tracing-examples-vue3)
|
|
21
|
+
|
|
22
|
+
## 演示
|
|
23
|
+
### 事件监听
|
|
24
|
+
<img src="https://github.com/M-cheng-web/image-provider/raw/main/web-tracing/image.4388hbrc1gc0.jpg" width="1200" alt="logo" />
|
|
25
|
+
|
|
26
|
+
### 错误监听
|
|
27
|
+
<img src="https://github.com/M-cheng-web/image-provider/raw/main/web-tracing/Oct-11-2023-15-43-53.788yqv47x3k0.gif" width="1200" alt="logo" />
|
|
28
|
+
|
|
29
|
+
### 资源监听
|
|
30
|
+
<img src="https://github.com/M-cheng-web/image-provider/raw/main/web-tracing/image.265x5n6f6ny8.jpg" width="1200" alt="logo" />
|
|
31
|
+
|
|
32
|
+
## 项目初衷
|
|
33
|
+
为了帮助开发们在公司平台上搭建一套前端监控平台
|
|
34
|
+
|
|
35
|
+
> 作者心声: 想降低一下前端在这方面耗费的时间与精力,此项目会尽量针对每个场景都提供解决方案;即使最后没用我这套,但从在这里对某些场景方案有了一些了解,我也很开心(为了方便大家移植代码所以没有分包,如果你有分包需求可联系我,干杯!)
|
|
36
|
+
|
|
37
|
+
## 亮点
|
|
38
|
+
提供了多种定制化api最大限度帮助你应付各个场景的业务,例如:
|
|
39
|
+
+ 提供钩子函数让你对数据精确把握
|
|
40
|
+
+ 提供本地化选项api,让开发手动控制去发送监控数据 - 节省带宽
|
|
41
|
+
+ 提供批量错误api,在遇到无限错误时融合批量错误信息 - 节省带宽
|
|
42
|
+
+ 提供抽样发送api - 节省带宽
|
|
43
|
+
+ 提供 错误/请求 事件的过滤api
|
|
44
|
+
+ 等等....
|
|
45
|
+
|
|
46
|
+
站在技术角度,因为明确此项目可能更多的是应用在公司平台上,大概率会二开,所以作者对项目结构以及代码都严格要求
|
|
47
|
+
+ 架构 - demo、核心sdk代码、文档都在同一个项目中,调试、部署都很方便
|
|
48
|
+
+ 封装 - sdk存在大量的重写或者监听,对此有统一流程
|
|
49
|
+
+ 响应式 - 项目内部实现了vue响应式,也应用在 options 对象中,相信你接触会后受益良多
|
|
50
|
+
+ 多版本 - 针对不同平台提供多个版本(目前只有js、vue2、vue3),受益于monorepo架构可一键发布
|
|
51
|
+
+ 内聚 - 目前核心功能的所有代码都没有分包,虽然monorepo架构支持,但作者认为目前分包不利于代码阅读以及二开方便
|
|
52
|
+
+ 文档/注释 - 完善的文档以及非常全的注释,力求帮助你快速了解这一切
|
|
53
|
+
|
|
54
|
+
## 功能列表
|
|
55
|
+
具体参见[CHANGELOG.md](https://github.com/M-cheng-web/web-tracing/blob/main/CHANGELOG.md)
|
|
56
|
+
|
|
57
|
+
## 未来方向
|
|
58
|
+
会写一套服务端(nest) + 后台查看监控数据平台(vue),有以下几点考量
|
|
59
|
+
+ 提供服务端能力(目前只是在采集端发力)
|
|
60
|
+
+ 可以在线体验此项目
|
|
61
|
+
+ 提供更多示例代码给开发们,再次降低这一套代码在公司的推广难度
|
|
62
|
+
+ 作者也想站在业务的角度多思考还能从哪些方面此项目还缺失哪些功能
|
|
63
|
+
|
|
64
|
+
针对首屏加载的监控做出更多精细化的东西,例如考虑sdk的绝对轻量化
|
|
65
|
+
|
|
66
|
+
## 联系我
|
|
67
|
+
<img align="left" width="180" src="https://github.com/M-cheng-web/image-provider/raw/main/web-tracing/image.19hrnxwgkdpc.jpg" />
|
|
68
|
+
|
|
69
|
+
- 如果对此项目有疑虑或者有优化点,欢迎与我讨论(有沟通群)
|
|
70
|
+
- Bug 反馈请直接去 Github 上面提 Issues,我会实时收到邮件提醒前去查看
|
|
71
|
+
|
|
72
|
+
<br/>
|
|
73
|
+
<br/>
|
|
74
|
+
<br/>
|
|
75
|
+
<br/>
|
|
76
|
+
<br/>
|
|
77
|
+
|
|
78
|
+
## 🙏🙏🙏 点个Star
|
|
79
|
+
|
|
80
|
+
**如果您觉得这个项目还不错, 可以在 [Github](https://github.com/M-cheng-web/web-tracing) 上面帮我点个`star`, 支持一下作者ヾ(◍°∇°◍)ノ゙**
|
|
81
|
+
|
|
82
|
+
<br/>
|
|
83
|
+
|
|
84
|
+
## 贡献者
|
|
85
|
+
|
|
86
|
+
<a href="https://github.com/M-cheng-web/web-tracing/graphs/contributors">
|
|
87
|
+
<img src="https://contrib.rocks/image?repo=M-cheng-web/web-tracing" />
|
|
88
|
+
</a>
|
|
89
|
+
|
|
90
|
+
<br/>
|
|
91
|
+
|
|
92
|
+
## 特别感谢
|
|
93
|
+
+ [xy-sea](https://github.com/xy-sea)为我提供了很多好主意,这是他的关于[监控平台文章以及blog](https://github.com/xy-sea/blog/blob/main/markdown/%E4%BB%8E0%E5%88%B01%E6%90%AD%E5%BB%BA%E5%89%8D%E7%AB%AF%E7%9B%91%E6%8E%A7%E5%B9%B3%E5%8F%B0%EF%BC%8C%E9%9D%A2%E8%AF%95%E5%BF%85%E5%A4%87%E7%9A%84%E4%BA%AE%E7%82%B9%E9%A1%B9%E7%9B%AE.md),写的很好受益匪浅
|
|
94
|
+
+ [wangshitao929@163.com](wangshitao929@163.com) - 特别赞助
|
|
95
|
+
+ [rrweb](https://github.com/rrweb-io/rrweb) - sdk内部使用其帮助错误录屏
|
|
96
|
+
+ [fingerprintjs v3.4.1](https://github.com/fingerprintjs/fingerprintjs) - sdk内部采用了其离线版本,用于标识唯一用户
|
|
97
|
+
+ [webrtc-ip v3.0.1](https://github.com/joeymalvinni/webrtc-ip) - sdk内部采用了其离线版本,用于获取公网ip
|