-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
59 lines (54 loc) · 2.16 KB
/
popup.js
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
document.addEventListener('DOMContentLoaded', function () {
const resultDiv = document.getElementById('result');
const checkBtn = document.getElementById('checkBtn');
const downloadBtn = document.getElementById('downloadBtn');
checkBtn.addEventListener('click', function() {
resultDiv.textContent = 'Checking...';
resultDiv.style.color = 'black';
chrome.runtime.sendMessage({ type: 'checkFingerprinting' }, (response) => {
if (chrome.runtime.lastError) {
// Handle messaging errors
resultDiv.textContent = 'Communication error: ' + chrome.runtime.lastError.message;
resultDiv.style.color = 'red';
console.error('Communication error:', chrome.runtime.lastError);
return;
}
if (!response) {
// Handle null or undefined response
resultDiv.textContent = 'No response received from the background script.';
resultDiv.style.color = 'orange';
console.warn('No response received');
return;
}
if (response.hasOwnProperty('isFingerprinting')) {
// Properly handle the expected response
if (response.isFingerprinting) {
resultDiv.textContent = 'Fingerprinting detected';
resultDiv.style.color = 'red';
} else {
resultDiv.textContent = 'Fingerprinting not detected';
resultDiv.style.color = 'green';
}
} else {
// Handle unexpected response structure
resultDiv.textContent = 'Unexpected response format.';
resultDiv.style.color = 'orange';
console.warn('Unexpected response format:', response);
}
});
});
downloadBtn.addEventListener('click', function() {
console.log('Download Logs button clicked');
chrome.runtime.sendMessage({ type: 'downloadLogs' }, () => {
if (chrome.runtime.lastError) {
// Handle messaging errors
resultDiv.textContent = 'Download error: ' + chrome.runtime.lastError.message;
resultDiv.style.color = 'red';
console.error('Download error:', chrome.runtime.lastError);
return;
}
resultDiv.textContent = 'Logs downloaded';
resultDiv.style.color = 'blue';
});
});
});