I'm new to implementing chrome extensions and I want to be able to get a cookie value from a site, delete it, reload the site, and then get a different cookie value. The issue is that I can get the cookie value that I want, but when I remove the cookie and reload the page to get that value again it comes back as the same one instead of generating a new value. My thoughts are that the way I'm removing my cookie is wrong. If anyone could help me figure out where I'm going wrong, that would help a bunch, thanks!
manifest.json
{
"manifest_version": 2,
"name": "xxxx",
"version": "1.0",
"permissions": [
"cookies",
"tabs",
"activeTab",
"http://*/*",
"https://*/*",
"<all_urls>"
],
"content_scripts": [
{
"matches": [
"<all_urls>"
],
"js": ["content.js"]
}
],
"background": {
"scripts": ["background.js"]
},
"browser_action": {
"default_icon": "cookie.png"
}
}
background.js
function cookieInfo(){
chrome.cookies.getAll({url: url, name: "specificCookie"}, (cookies) => {
//console.log("getting cookie")
console.log(cookies[0].value)
//return cookies
});
}
function removeCookies(){
chrome.cookies.getAll({domain: url}, function(cookies) {
console.log('Cookies Removed')
clearCookies(cookies);
});
}
function clearCookies(cookies) {
// iterate on cookie to get cookie detail
for (let i = 0; i < cookies.length; i++) {
let url = "https" + (cookies[i].secure ? "s" : "") + "://" + cookies[i].domain + cookies[i].path;
let cname = cookies[i].name;
// delete cookie
chrome.cookies.remove({
url: url,
name: cname
});
}
}
chrome.browserAction.onClicked.addListener(buttonClicked);
function buttonClicked(tab){
cookieInfo();
removeCookies();
}
content.js
chrome.runtime.onMessage.addListener(gotMessage);
function gotMessage(req, sender, res){
console.log(req);
}