Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migrate list-cookies extension to manifest version 3 #559

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 25 additions & 24 deletions list-cookies/cookies.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,40 @@
function getActiveTab() {
chrome.tabs.query({currentWindow: true, active: true}, function(tabs) {
showCookiesForTab(tabs);
});
}

function showCookiesForTab(tabs) {
//get the first tab object in the array
let tab = tabs.pop();
if (tabs.length === 0) {
return; // No tabs found, likely an error condition
}

//get all cookies in the domain
let gettingAllCookies = browser.cookies.getAll({url: tab.url});
gettingAllCookies.then((cookies) => {
// Get the first tab object in the array
let tab = tabs[0]; // Changed from pop() to directly access the first element

//set the header of the panel
// Get all cookies in the domain
chrome.cookies.getAll({url: tab.url}, function(cookies) {
// Set the header of the panel
let activeTabUrl = document.getElementById('header-title');
let text = document.createTextNode("Cookies at: "+tab.title);
activeTabUrl.textContent = "Cookies at: " + tab.title; // Simplified textContent usage

let cookieList = document.getElementById('cookie-list');
activeTabUrl.appendChild(text);
cookieList.innerHTML = ''; // Clear previous entries

if (cookies.length > 0) {
//add an <li> item with the name and value of the cookie to the list
for (let cookie of cookies) {
// Add an <li> item with the name and value of the cookie to the list
cookies.forEach(function(cookie) {
let li = document.createElement("li");
let content = document.createTextNode(cookie.name + ": "+ cookie.value);
li.appendChild(content);
li.textContent = cookie.name + ": " + cookie.value; // Simplified textContent usage
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);
p.textContent = "No cookies in this tab."; // Simplified textContent usage
cookieList.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);
// Call getActiveTab to start the process
getActiveTab();
Loading