-3

how get cookies allowed, those that are shown in the "lock" of the browser?

I get a redirect in my page and I need to get a certain SESSION_ID that is passed through certain layers of the API...

Several articles and answers show how to get it from the browser's storage but this type of cookie is not saved there... An example image below:

https://i.sstatic.net/3pjcP.png

1
  • Not all cookies are accessible through JS Commented Nov 8, 2021 at 13:22

1 Answer 1

-1

read this

Read a Cookie with JavaScript

With JavaScript, cookies can be read like this:

let x = document.cookie;

Some nice functions

Get a Cookie

function getCookie(cname) {
  let name = cname + "=";
  let decodedCookie = decodeURIComponent(document.cookie);
  let ca = decodedCookie.split(';');
  for(let i = 0; i <ca.length; i++) {
    let c = ca[i];
    while (c.charAt(0) == ' ') {
      c = c.substring(1);
    }
    if (c.indexOf(name) == 0) {
      return c.substring(name.length, c.length);
    }
  }
  return "";
}

Set a Cookie

function setCookie(cname, cvalue, exdays) {
  const d = new Date();
  d.setTime(d.getTime() + (exdays*24*60*60*1000));
  let expires = "expires="+ d.toUTCString();
  document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/";
}
Sign up to request clarification or add additional context in comments.

1 Comment

if this doesnt work, then look up localStorage api

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.