-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcookies.js
More file actions
34 lines (33 loc) · 906 Bytes
/
cookies.js
File metadata and controls
34 lines (33 loc) · 906 Bytes
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
export const exportCookies = async (customDomain = null) => {
let domain = customDomain;
if (!domain) {
const [tab] = await browser.tabs.query({
active: true,
currentWindow: true,
});
const url = new URL(tab.url);
domain = url.hostname;
}
const cookies = await browser.cookies.getAll({ domain: domain });
return cookies
.map((cookie) => {
const domainField = cookie.domain.startsWith(".")
? cookie.domain
: "." + cookie.domain;
const flag = cookie.hostOnly ? "FALSE" : "TRUE";
const secure = cookie.secure ? "TRUE" : "FALSE";
const expiration = cookie.expirationDate
? Math.floor(cookie.expirationDate)
: "0";
return [
domainField,
flag,
cookie.path,
secure,
expiration,
cookie.name,
cookie.value,
].join("\t");
})
.join("\n");
};