It seems to me that setting a url encoded cookie with browser.cookie.set works great at saving the value in it’s url encoded state.
However, getting the same cookie decodes the value for some reason?
Is this expected? I could not find any documentation on it.
let cookie = `bizbaz=${encodeURIComponent('foo:bar')}`
// cookie = 'bizbaz=foo%3Abar'
browser.cookie.set(cookie);
const cookie2 = await browser.cookie.get('bizbaz');
// cookie2 = 'foo:bar'
1 Like
Hello Joey,
Whenever a cookie name is passed in the Shopify’s cookie API, the full cookie string gets parsed for you and you get the decoded value back.
If you wish to get the cookie string as-is, you can call the same API without a cookie name string and you would get the same as calling document.cookie
on the top frame.
await browser.cookie.set(`bizbaz=${encodeURIComponent('foo:bar')}`);
await browser.cookie.get('bizbaz');
// => 'foo:bar'
await browser.cookie.get();
// => 'bizbaz=foo%3Abar; other_cookie=value;'
The reason the value needs to be encoded when calling set
is that the API expects a valid cookie string to be able to support all optional cookie configurations at the same time.
await browser.cookie.set(
'foo=bar; expires=Fri, 31 Dec 9999 23:59:59 GMT; SameSite=None; Secure'
);
Hope this helps.