I have some trouble working with cookies via chrome extension from popup script.
popup.js content:
document.addEventListener('DOMContentLoaded', () => {
function cookieinfo() {
chrome.cookies.getAll({url: 'http://localhost:8080'}, function(cookie) {
console.log('Found cookie: ', cookie)
if (cookie == null)
return;
fetch('http://localhost:8080', {credentials: 'include'}).then((response) => {
// do some stuff
return response;
});
});
}
window.onload=cookieinfo;
}, false);
Steps that I perform:
- Log into my application on localhost (So I get the cookies)
- Open the popup (so popup.js is executed)
- I see in the console log that chrome found necessary cookies
- Server says that ingoing request has empty cookies
- I refresh page of localhost application
- I am logged out now
Maybe someone knows what I'm doing wrong?
Edit:
It seems that the reason is that my cookie has parameters HttpOnly=true
and SameSite=Lax
(related link). I can see another cookies in the server log. But due to this thread all cookies will be sent if credentials
parameter is set to include
, even httpOnly cookies. Also I tried to send it to 127.0.0.1 instead of localhost due to this answer with the same result.
I can't set httpOnly
to false. This is forced by framework. Somebody know how to fix it?
Edit2:
I finally installed Cookie editor and found out that the SameSite=Lax
is the reason. If I set it to No Restriction
then I will see it on the server side. Unfortunately, the framework I'm using only allows Lax
and Strict
options (Chrome extension fails with both). Does anyone know how to send Lax cookies from the Chrome extension?