MCPcopy Create free account
hub / github.com/L-excellence/monitor-sdk / injectLongTask

Function injectLongTask

modules/longTask.ts:6–30  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

4import tracker from "../utils/tracker";
5
6export 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}

Callers 1

index.tsFile · 0.85

Calls 3

getLastEventFunction · 0.85
sendMethod · 0.80
getSelectorFunction · 0.50

Tested by

no test coverage detected