mirror of
https://github.com/mdn/webextensions-examples.git
synced 2026-04-16 06:18:35 +02:00
* Replace var with let in examples store-collected-images/webextension-plain/deps/uuidv4.js * Reverted third–party code
40 lines
1.3 KiB
JavaScript
40 lines
1.3 KiB
JavaScript
function showCookiesForTab(tabs) {
|
|
//get the first tab object in the array
|
|
let tab = tabs.pop();
|
|
|
|
//get all cookies in the domain
|
|
let gettingAllCookies = browser.cookies.getAll({url: tab.url});
|
|
gettingAllCookies.then((cookies) => {
|
|
|
|
//set the header of the panel
|
|
let activeTabUrl = document.getElementById('header-title');
|
|
let text = document.createTextNode("Cookies at: "+tab.title);
|
|
let cookieList = document.getElementById('cookie-list');
|
|
activeTabUrl.appendChild(text);
|
|
|
|
if (cookies.length > 0) {
|
|
//add an <li> item with the name and value of the cookie to the list
|
|
for (let cookie of cookies) {
|
|
let li = document.createElement("li");
|
|
let content = document.createTextNode(cookie.name + ": "+ cookie.value);
|
|
li.appendChild(content);
|
|
cookieList.appendChild(li);
|
|
}
|
|
} else {
|
|
let p = document.createElement("p");
|
|
let content = document.createTextNode("No cookies in this tab.");
|
|
let parent = cookieList.parentNode;
|
|
|
|
p.appendChild(content);
|
|
parent.appendChild(p);
|
|
}
|
|
});
|
|
}
|
|
|
|
//get active tab to run an callback function.
|
|
//it sends to our callback an array of tab objects
|
|
function getActiveTab() {
|
|
return browser.tabs.query({currentWindow: true, active: true});
|
|
}
|
|
getActiveTab().then(showCookiesForTab);
|