0

I'm using the following code to retrieve a value from a cookie on example.com. The code works correctly and retrieves the value from the cookie and is logging it in the console as intended. How do I turn cookie.value into a variable to use it elsewhere outside the chrome.cookies.get statement?

chrome.cookies.get({url: "https://www.example.com/", name: "preferences"}, cookie => {
    console.log('got a cookie!', cookie);
    console.log(cookie.value);
});

Thanks in advance for your help.

  • Assign `cookie.value` to a global variable. – Barmar Jan 03 '20 at 03:38
  • See also [Why is my variable unaltered after I modify it inside of a function? - Asynchronous code reference](//stackoverflow.com/q/23667086) – wOxxOm Jan 03 '20 at 06:25

0 Answers0