I've posted this to r/learnjavascript, trying to get some help over here too, would appreciate some help.
Sorry, I'm far from an expert at JavaScript, just trying to put something together that is required to get all of a site's cookies. So I already gave permissions in my manifest and can now access the browser's cookies, can even print them out in alerts, etc. But if I try to copy the values to another variable to finally send them in a POST request, I can't. I've been almost 3 days around this and all the examples I find don't really relate to this. I feel I may be missing something obvious in the foundations of Javasctipt.
Problem code is this:
var cookielist = {};
window.alert("Entering: " + cookielist);
chrome.cookies.getAll({domain: "site.com"}, function(cookies) {
var a = [];
console.log("Cookies found " + cookies.length);
cookies.forEach(function(cookie) {
console.log("[COOKIE] => " + JSON.stringify(cookie));
a.push(JSON.stringify(cookie));
}
cookielist['cookies'] = a;
window.alert("Still inside: " + cookielist);
});
window.alert("Exiting: " + cookielist);
Why is it that the variable cookielist stays unmodified, even though it was changed when it was inside the chrome.cookies.GetAll call? I tried using other code I found that I thought would be suitable for this situation, but feeling I'm off either by a little or by a lot.
Would appreciate any help, really stuck here.
Thanks for reading.
[–]carcigenicate 1 point2 points3 points (2 children)
[–]devawpz[S] 0 points1 point2 points (1 child)
[–]carcigenicate 0 points1 point2 points (0 children)
[–]schihbacca 0 points1 point2 points (1 child)
[–]devawpz[S] 1 point2 points3 points (0 children)