-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
27 lines (23 loc) · 1.17 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
// Listen for messages from content scripts
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message.action === 'mergeCookies') {
let sessionId = '';
// Get session ID cookie using chrome.cookies.get
chrome.cookies.get({ "url": 'https://fap.fpt.edu.vn/Student.aspx', "name": 'ASP.NET_SessionId' }, function (cookie) {
if (cookie) {
sessionId = `${cookie.name}=${cookie.value}`;
}
// Get cookies from Chrome API
chrome.cookies.getAll({ domain: "fap.fpt.edu.vn" }, cookies => {
// Extract cookie values from the cookies array
const cookieString = cookies.map(cookie => `${cookie.name}=${cookie.value}`).join('; ');
// Merge the cookies from document.cookie and Chrome API
const updatedCookie = `${message.cookie};${sessionId};${cookieString}`;
// Send back the updated cookie string to the content script
sendResponse(updatedCookie);
});
});
// Return true to indicate that we want to use sendResponse asynchronously
return true;
}
});