-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfetch.html
32 lines (28 loc) · 1.07 KB
/
fetch.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
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>
(async function(){
const button = document.createElement('button');
const urlField = document.createElement('input');
urlField.type = 'text';
urlField.value = 'http://localhost:8000';
urlField.style.width = '400px';
button.innerText = 'Press';
button.style.width = '400px';
const body = document.body;
body.appendChild(urlField);
body.appendChild(button);
button.addEventListener('click', async () => {
const time = performance.now();
const response = await fetch(urlField.value, { mode: 'no-cors'});
const result = await response.blob();
button.innerText = `Time: ${performance.now() - time} ms, Bytes: ${result.size}`;
console.log(result);
})
})()
</script>
</body>
</html>