UNPKG

monitor-test

Version:

网页性能监控 18 项数据指标,浏览器信息,错误收集上报方案,前端工程化。

43 lines (39 loc) 933 B
import { send } from '../../sender/send' import { timeFixed } from '../../utils/time' import { stores, pre } from '../../config' import { single } from '../../utils' export function recordResource() { const data = window.performance.getEntriesByType('resource') const resource = { script: [], img: [], link: [], css: [] } data.forEach((item) => { const arr = resource[item.initiatorType] if (!arr) { return } const info = { name: item.name, ...timeFixed({ duration: item?.duration ?? '' }), size: item.transferSize, protocol: item.nextHopProtocol } if (item.initiatorType === 'link' && item.name.includes('.css')) { resource['css'].push(info) } else { arr.push(info) } }) send( stores.performance, { type: 'performance', subType: 'resource', ...single('res', resource) }, pre.performance ) }