Electron Documentation1.7.9

Docs / API / Cookies

Class: Cookies

Query and modify a session’s cookies.

Process: Main

Instances of the Cookies class are accessed by using cookies property of a Session.

For example:

const {session} = require('electron')

// Query all cookies.
session.defaultSession.cookies.get({}, (error, cookies) => {
  console.log(error, cookies)
})

// Query all cookies associated with a specific url.
session.defaultSession.cookies.get({url: 'http://www.github.com'}, (error, cookies) => {
  console.log(error, cookies)
})

// Set a cookie with the given cookie data;
// may overwrite equivalent cookies if they exist.
const cookie = {url: 'http://www.github.com', name: 'dummy_name', value: 'dummy'}
session.defaultSession.cookies.set(cookie, (error) => {
  if (error) console.error(error)
})

Instance Events

The following events are available on instances of Cookies:

Event: ‘changed’

Emitted when a cookie is changed because it was added, edited, removed, or expired.

Instance Methods

The following methods are available on instances of Cookies:

cookies.get(filter, callback)

Sends a request to get all cookies matching details, callback will be called with callback(error, cookies) on complete.

cookies.set(details, callback)

Sets a cookie with details, callback will be called with callback(error) on complete.

cookies.remove(url, name, callback)

Removes the cookies matching url and name, callback will called with callback() on complete.

cookies.flushStore(callback)

Writes any unwritten cookies data to disk.


See something that needs fixing? Propose a change on the source.
Need a different version of the docs? See the available versions or community translations.
Want to search all the documentation at once? See all of the docs on one page.