-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
40 lines (37 loc) · 1.36 KB
/
Copy pathcontent.js
File metadata and controls
40 lines (37 loc) · 1.36 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
33
34
35
36
37
38
39
40
// Content script that runs in the page context and can access cookies
// This bridges the gap between the page (with HttpOnly cookies) and the extension
// Listen for messages from the background script
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
if (request.action === 'fetchWithCookies') {
// Fetch the URL using the page's context, which has access to HttpOnly cookies
fetch(request.url, {
credentials: 'include', // This will include HttpOnly cookies
headers: {
'Accept': 'application/x-bittorrent,*/*'
}
})
.then(response => {
if (!response.ok) {
throw new Error(`HTTP ${response.status}`);
}
return response.blob();
})
.then(blob => {
// Convert blob to base64
const reader = new FileReader();
reader.onloadend = () => {
const base64 = reader.result.split(',')[1];
sendResponse({ success: true, base64: base64 });
};
reader.onerror = () => {
sendResponse({ success: false, error: 'Failed to read blob' });
};
reader.readAsDataURL(blob);
})
.catch(error => {
sendResponse({ success: false, error: error.message });
});
return true; // Keep the message channel open for async response
}
});
console.log('qBittorrent content script loaded');