-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
211 lines (188 loc) · 6.69 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Browser Visualization</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/css/bulma.min.css">
<link href="https://cdnjs.cloudflare.com/ajax/libs/jsoneditor/10.0.0/jsoneditor.min.css" rel="stylesheet" type="text/css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jsoneditor/10.0.0/jsoneditor.min.js"></script>
<style>
.grid-container {
visibility: hidden;
display: grid;
height: 100vh;
width: 100vw;
grid-column-gap: 0px;
grid-row-gap: 0px;
grid-template:
"b c" 50%
"a a" 50% / 1fr 1fr;
}
#video {
grid-area: a;
}
#video-input {
}
#video-player {
width: 100%;
height: 100%;
object-fit: scale-down;
background-color: black;
}
#network-table {
grid-area: b;
cursor: pointer;
overflow: scroll;
}
.selected-row {
background-color: lightgreen; /* Or any desired color */
}
#network-detail {
grid-area: c;
}
</style>
</head>
<body>
<div id="upload-container">
<input class="input" type="file" accept="video/*" id="video-input">
<input class="input" type="file" accept="application/JSON" id="network-input">
</div>
<div class="grid-container" id="viz-container">
<div class="grid-item" id="video">
<video id="video-player" controls></video>
</div>
<div class="grid-item" id="network-table">
<table class="table is-fullwidth is-hoverable">
<thead>
<tr>
<th>Timer</th>
<th>Status</th>
<th>Method</th>
<th>URL</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</div>
<div class="grid-item" id="network-detail"></div>
</div>
<script>
const uploadContainer = document.querySelector("#upload-container");
const vizContainer = document.querySelector("#viz-container");
// ---> Start of network data handling
const networkInput = document.querySelector("#network-input");
const networkTable = document.querySelector('#network-table');
const networkTableBody = document.querySelector('#network-table tbody');
const networkDetail = document.querySelector('#network-detail');
const networkDetailEditor = new JSONEditor(networkDetail, {})
const networkDetailDelaySeconds = 5;
let networkBucket = null;
function onNewNetworkData(raw) {
// Bucketize records to relative seconds from the start timestamp
const startTimestamp = raw.startTimestamp;
const records = raw.records;
records.sort((a, b) => a.timestamp - b.timestamp);
networkBucket = {};
for (const record of records) {
const key = Math.floor((record.timestamp - startTimestamp) / 1000);
const bucket = networkBucket[key] || [];
bucket.push(record);
networkBucket[key] = bucket;
}
console.log(networkBucket);
onSubmit();
}
networkInput.addEventListener('change', (event) => {
const file = event.target.files[0];
const reader = new FileReader();
reader.onload = (event) => {
try {
onNewNetworkData(JSON.parse(event.target.result));
} catch (error) {
console.error('Error parsing JSON:', error);
}
};
reader.readAsText(file);
});
function onSelectRow(row) {
if (!row) {
return;
}
const selectedDataID = row.getAttribute("data-id");
console.log(`Selected: ${selectedDataID}`)
const tokens = selectedDataID.split("-");
const elapsed = parseInt(tokens[0]);
const recordIdx = parseInt(tokens[1]);
const record = networkBucket[elapsed][recordIdx];
console.log(record);
networkDetailEditor.set(record)
}
networkTable.addEventListener('click', (event) => {
if (event.target.tagName === 'TD') {
const clickedRow = event.target.closest('tr');
const previousRow = networkTable.querySelector('.selected-row');
if (previousRow) {
previousRow.classList.remove('selected-row');
}
clickedRow.classList.add('selected-row');
onSelectRow(clickedRow);
}
});
function networkOnSeek(elapsed) {
const rows = [];
const elapsedStart = elapsed - networkDetailDelaySeconds;
const elapsedEnd = elapsed;
for (let currentTime = elapsedStart; currentTime <= elapsedEnd; currentTime++) {
const records = networkBucket[currentTime] || [];
for (let recordIdx = 0; recordIdx < records.length; recordIdx++) {
const record = records[recordIdx];
const contentType = record.responseHeaders["content-type"] || "";
const jsonOnly = contentType.toLowerCase().includes("json");
const fetchOrXhrOnly = ["fetch", "xhr"].includes(record.requestType);
if (record.requestMethod === "OPTIONS" || !fetchOrXhrOnly || !jsonOnly) {
continue;
}
rows.push(`
<tr data-id="${currentTime}-${recordIdx}">
<td>${currentTime - elapsedStart}s</td>
<td>${record.responseStatus}</td>
<td>${record.requestMethod}</td>
<td>${record.requestUrl}</td>
</tr>
`)
}
}
networkTableBody.innerHTML = rows.join("");
}
// <--- End of network data handling
// ---> Start of video/seeker handling
const videoInput = document.querySelector("#video-input");
const videoPlayer = document.querySelector("#video-player");
videoInput.addEventListener('change', (event) => {
const file = event.target.files[0];
const url = URL.createObjectURL(file);
videoPlayer.src = url;
onSubmit();
});
videoPlayer.addEventListener("timeupdate", () => {
console.log(videoPlayer.currentTime)
const elapsed = Math.floor(videoPlayer.currentTime);
networkOnSeek(elapsed);
});
// <--- End of video/seeker handling
// ---> Start of upload handling
function onSubmit() {
console.log("On submit")
console.log(networkBucket)
console.log(videoPlayer.src)
if (networkBucket && videoPlayer.src) {
uploadContainer.style.display = 'none';
vizContainer.style.visibility = 'visible';
}
}
// <--- End of upload handling
</script>
</body>
</html>