forked from makiuchi-d/copycookies
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpopup.js
58 lines (49 loc) · 1.75 KB
/
popup.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
(async function() {
let [tab] = await chrome.tabs.query({active: true, lastFocusedWindow: true});
const tabUrl = tab.url;
// Promise to retrieve cookies with partition key
const cookiesWithPartitionKeyPromise = new Promise((resolve, reject) => {
chrome.cookies.getAll({
url: tabUrl,
partitionKey: {
topLevelSite: new URL(tabUrl).origin
}
}, cookies => {
resolve(cookies);
});
});
// Promise to retrieve cookies without partition key
const cookiesWithoutPartitionKeyPromise = new Promise((resolve, reject) => {
chrome.cookies.getAll({
url: tabUrl
}, cookies => {
resolve(cookies);
});
});
// Wait for both promises to resolve
const [cookiesWithPartitionKey, cookiesWithoutPartitionKey] = await Promise.all([
cookiesWithPartitionKeyPromise,
cookiesWithoutPartitionKeyPromise
]);
// Combine cookies from both arrays
const allCookies = [...cookiesWithPartitionKey, ...cookiesWithoutPartitionKey];
chrome.runtime.getPlatformInfo(platformInfo => {
var area = document.createElement('textarea');
area.style.position = 'absolute';
area.style.border = '0';
area.style.padding = '0';
area.style.margin = '0';
area.style.height = '1px';
area.style.top = '-10px';
const data = {
cookies: allCookies,
userAgent: navigator.userAgent
};
area.innerText = JSON.stringify(data);
document.body.appendChild(area, document.body.firstChild);
area.focus();
area.select();
document.execCommand("copy");
document.body.removeChild(area);
});
})();