-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpopup.js
More file actions
26 lines (25 loc) · 850 Bytes
/
popup.js
File metadata and controls
26 lines (25 loc) · 850 Bytes
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
document.addEventListener("DOMContentLoaded", async () => {
const [tab] = await chrome.tabs.query({ active: true, currentWindow: true });
if (tab) {
try {
const firstByteAsString = await fetchFirstByteAsString(tab.url);
document.getElementById(
"byteValue"
).textContent = `First byte: ${firstByteAsString}`;
} catch (error) {
document.getElementById(
"byteValue"
).textContent = `Error: ${error.message}`;
console.error("Fetch error:", error.message);
}
}
});
async function fetchFirstByteAsString(url) {
const response = await fetch(url);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
const buffer = await response.arrayBuffer();
const uint8Array = new Uint8Array(buffer);
return uint8Array[0].toString(2).padStart(8, "0");
}