-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
32 lines (27 loc) · 1.18 KB
/
background.js
File metadata and controls
32 lines (27 loc) · 1.18 KB
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
// Background script for JS & Endpoint Scanner
// Handles cross-origin fetching to bypass CORS/CSP
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === 'fetchScript') {
fetch(request.url, {
signal: AbortSignal.timeout(8000), // Slightly longer timeout for background
headers: { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) Firefox/130.0' }
})
.then(async response => {
if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`);
const contentLength = response.headers.get('content-length');
const code = await response.text();
sendResponse({
success: true,
code: code,
length: contentLength || code.length
});
})
.catch(error => {
sendResponse({ success: false, error: error.message });
});
return true; // Keep message channel open for async response
}
});
chrome.runtime.onInstalled.addListener(() => {
console.log('JS & Endpoint Scanner extension installed.');
});