()
| 4 | import tracker from "../utils/tracker"; |
| 5 | |
| 6 | export default function injectLongTask() { |
| 7 | if (PerformanceObserver) { |
| 8 | const observerLongTask = new PerformanceObserver(list => { |
| 9 | list.getEntries().forEach(entry => { |
| 10 | // 执行时长大于 100 ms |
| 11 | if (entry.duration > 100) { |
| 12 | const lastEvent = getLastEvent(); |
| 13 | |
| 14 | const log: LongTaskLog = { |
| 15 | type: "longTask", |
| 16 | startTime: entry.startTime, // 开始时间 |
| 17 | duration: entry.duration, // 持续时间 |
| 18 | selector: lastEvent ? getSelector() : "", |
| 19 | eventType: lastEvent?.type, |
| 20 | }; |
| 21 | console.log("longTask log: ", log); |
| 22 | |
| 23 | tracker.send(log); |
| 24 | } |
| 25 | }); |
| 26 | }); |
| 27 | |
| 28 | observerLongTask.observe({ entryTypes: ["longtask"] }); |
| 29 | } |
| 30 | } |
no test coverage detected