-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathbackground.js
67 lines (58 loc) · 1.79 KB
/
background.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
60
61
62
63
64
65
66
67
let port = null;
let statusCheckInterval = null;
function connectNativeHost() {
port = chrome.runtime.connectNative('com.webtrufflehog');
port.onMessage.addListener((response) => {
if (response.findings && response.findings.length > 0) {
// Add timestamp and URL to each finding
const findings = response.findings.map(finding => ({
...finding,
timestamp: Date.now(),
url: response.url
}));
console.log('Secrets found:', findings);
chrome.storage.local.set({
[`findings_${response.id}`]: findings
});
} else if (response.status !== undefined) {
// Store queue size in storage
chrome.storage.local.set({ queueSize: response.status });
}
});
port.onDisconnect.addListener(() => {
console.error('Disconnected from native host:', chrome.runtime.lastError);
port = null;
if (statusCheckInterval) {
clearInterval(statusCheckInterval);
}
});
// Start periodic status checks
statusCheckInterval = setInterval(() => {
if (port) {
port.postMessage({ status: 'check' });
}
}, 2000); // Check every 2 seconds
}
// Listen for web requests
chrome.webRequest.onCompleted.addListener(
(details) => {
if (!port) {
connectNativeHost();
}
// Filter out binary formats and images
const contentType = details.responseHeaders?.find(h =>
h.name.toLowerCase() === 'content-type'
)?.value || '';
if (contentType.includes('text/')||
contentType.includes('script/') ||
contentType.includes('application/')) {
port.postMessage({
id: details.requestId,
url: details.url,
type: details.type
});
}
},
{ urls: ["<all_urls>"] },
["responseHeaders"]
);