crunk1
crunk1

Reputation: 2818

chrome.cookies.SetDetails confusing path/url parameter documention/behavior

Running on Chrome Version 133.0.6943.126

See chrome.cookies.set(details, callback?) documentation here.

In the details.path parameter description, it states:

The path of the cookie. Defaults to the path portion of the url parameter.

And in the details.url parameter description, it states:

The request-URI to associate with the setting of the cookie. This value can affect the default domain and path values of the created cookie. If host permissions for this URL are not specified in the manifest file, the API call will fail.

My understanding of this documentation was that if I provide a url of https://example.com/foo and DON'T provide a path, that the cookie path will be set to /foo.

However, I noticed that path is being set to /. Am I misunderstanding the documentation?

Minimal test

In my extension's service worker's console, when I run

await chrome.cookies.set({ name: 'hello', value: 'world', expirationDate: Date.now() / 1000 + 3600, url: 'https://example.com/foo' })

the result is

{
  domain: "example.com",
  expirationDate: 1740647880.071,
  hostOnly: true,
  httpOnly: false,
  name: "hello",
  path: "/",                      // why "/"? why not "/foo"?
  sameSite: "unspecified",
  secure: false,
  session: false,
  storeId: "0",
  value: "world"
}

Upvotes: 0

Views: 26

Answers (0)

Related Questions