1

The chrome.cookies.set API receive url as one of its parameter, from which cookie's domain and path is calculated.

For example, if url's value is https://stackoverflow.com, then domain is stackoverflow.com, while path is /.

The issue is, how to set a cookie with stackoverflow's subdomain: .stackoverflow.com. In other work, we want to have a cookie whose domain value is .stackoverflow.com

I've tried two approaches, none of them work.

  1. { url: https//*.stackoverflow.com }
  2. { url: https//.stackoverflow.com }
  • Specify `domain: 'stackoverflow.com', url: 'https://stackoverflow.com'`. – wOxxOm Jun 20 '20 at 07:59
  • Doesn't work @wOxxOm, The current cookie won't be edited, but A new cookie whose domain is `stackoverflow.com` will be inserted. This is not the desired behavior. :( – Cảnh Toàn Nguyễn Jun 20 '20 at 11:58
  • Delete the current cookie and set the new one? – wOxxOm Jun 20 '20 at 12:01
  • Yes I think about this strategy. But somehow can't set `domain` value to be a subdomain `.stackoverflow.com`. Its value is always `stackoverflow.com`. – Cảnh Toàn Nguyễn Jun 20 '20 at 12:09
  • 1
    There's no need for the leading dot when you use `domain`. It already applies to all sub-domains. – wOxxOm Jun 20 '20 at 12:16
  • Yes it does. I found the stackoverflow's related topic here. Posting this for future reference. https://stackoverflow.com/questions/18492576/share-cookie-between-subdomain-and-domain – Cảnh Toàn Nguyễn Jun 20 '20 at 12:21
  • CảnhToànNguyễn have you been able to set the cookie from Chrome extension? `domain` param is not documented in the API. And it does not work for me in Chrome v91 – user1635430 Jul 03 '21 at 15:07

0 Answers0