Skip to content

Instantly share code, notes, and snippets.

@zpbx
zpbx / log-web-pref.js
Created March 21, 2017 09:23
在页面中获取两个关键指标
function test(cond) {
'use strict'
let data = {}
data.N0 = performance.timing.navigationStart
data.L0 = performance.timing.loadEventStart
data.P = window.chrome.loadTimes().firstPaintTime * 1000
data.metric1 = data.P - data.N0
data.metric2 = data.L0 - data.N0
console.log(`${cond} | ${data.metric1} | ${data.metric2}`)
}
@zpbx
zpbx / web-perf-grafana.js
Created March 16, 2017 09:40
把性能看板中的历史数据输出到控制台
document.body.onclick = function () {
const wrapper = document.querySelector('.grafana-tooltip')
if (!wrapper) {
console.error('no data!')
return
}
const date = wrapper.querySelector('.graph-tooltip-time').innerHTML.split(' ')[0]
const valueElements = Array.from(wrapper.querySelectorAll('.graph-tooltip-value'))
const values = valueElements.map((item) => {
const val = item.innerHTML || ''