-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemit_telemetry.html
63 lines (54 loc) · 1.54 KB
/
emit_telemetry.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
<!DOCTYPE html>
<head>
<meta charset="utf-8">
</head>
<body>
<button id="startButton">Start</button>
<div id="outcomeDiv"></div>
<div id="messageDiv"></div>
<script>
function getRandomString(size) {
const randomStringBlockSize = 65536;
const decoder = new TextDecoder("ISO-8859-2");
const getRandomStringBlock = array => {
crypto.getRandomValues(array);
return decoder.decode(array);
}
let string = "";
let quotient = size / randomStringBlockSize;
if (quotient) {
let array = new Uint8Array(randomStringBlockSize);
for (let i = 1; i <= quotient; i++) {
string += getRandomStringBlock(array);
}
}
let remainder = size % randomStringBlockSize;
if (remainder) {
let array = new Uint8Array(remainder);
string += getRandomStringBlock(array);
}
return string;
}
const twoMegs = 2 * 1024 * 1024;
const startHere = document.getElementById("startButton");
const outcomeHere = document.getElementById("outcomeDiv");
const messageHere = document.getElementById("messageDiv");
startHere.onclick = () => {
const data = {
key: "foo",
value: getRandomString(twoMegs),
};
let outcome = "Failure";
try {
localStorage.setItem(data.key, data.value);
} catch (err) {
outcome = "Success";
const msg = document.createTextNode(err.message);
messageHere.appendChild(msg);
console.log(err.message);
}
const content = document.createTextNode(outcome);
outcomeHere.appendChild(content);
};
</script>
</body>