Zum Inhalt springen

Class: Cookies

Class: Cookies

Abfragen und modifizieren von Session Cookies.

Process: Main
This class is not exported from the 'electron' module. It is only available as a return value of other methods in the Electron API.

Auf Instanzen der Cookies-Klasse wird über die Cookie-Eigenschaft einer Sitzung zugegriffen.

Ein Beispiel:

const { session } = require('electron')

// Durchsuche all Cookies.
.then((cookies) => {
}).catch((error) => {

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

// 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' }
.then(() => {
// success
}, (error) => {


The following events are available on instances of Cookies:

Event: 'changed'

Kehrt zurück:

  • event Event
  • cookie Cookie - The cookie that was changed.
  • cause string - The cause of the change with one of the following values:
    • explicit - The cookie was changed directly by a consumer's action.
    • overwrite - The cookie was automatically removed due to an insert operation that overwrote it.
    • expired - The cookie was automatically removed as it expired.
    • evicted - The cookie was automatically evicted during garbage collection.
    • expired-overwrite - The cookie was overwritten with an already-expired expiration date.
  • removed boolean - true if the cookie was removed, false otherwise.

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

Beispiel Methoden

Die folgenden Methoden sind verfügbar in Instanzen von Cookies:


  • filter Objekt
    • url string (optional) - Retrieves cookies which are associated with url. Empty implies retrieving cookies of all URLs.
    • name string (optional) - Filters cookies by name.
    • domain string (optional) - Retrieves cookies whose domains match or are subdomains of domains.
    • path string (optional) - Retrieves cookies whose path matches path.
    • secure boolean (optional) - Filters cookies by their Secure property.
    • session boolean (optional) - Filters out session or persistent cookies.

Returns Promise<Cookie[]> - A promise which resolves an array of cookie objects.

Sends a request to get all cookies matching filter, and resolves a promise with the response.


  • details Objekt
    • url string - The URL to associate the cookie with. The promise will be rejected if the URL is invalid.
    • name string (optional) - The name of the cookie. Empty by default if omitted.
    • value string (optional) - The value of the cookie. Empty by default if omitted.
    • domain string (optional) - Die Domain des Cookie; dies wird mit einem vorhergehenden Punkt normalisiert, so dass es auch für Subdomains gilt. Empty by default if omitted.
    • path string (optional) - Der Pfad des Cookie. Empty by default if omitted.
    • secure boolean (optional) - Whether the cookie should be marked as Secure. Defaults to false unless Same Site=None attribute is used.
    • httpOnly boolean (optional) - Whether the cookie should be marked as HTTP only. Der Standardwert ist false.
    • expirationDate Double (optional) - The expiration date of the cookie as the number of seconds since the UNIX epoch. If omitted then the cookie becomes a session cookie and will not be retained between sessions.
    • sameSite string (optional) - The Same Site policy to apply to this cookie. Sein Wert kann nicht gesetzt , no_restriction, lax oder strict sein. Standard ist lax.

Returns Promise<void> - A promise which resolves when the cookie has been set

Sets a cookie with details.

cookies.remove(url, name)

  • url string - The URL associated with the cookie.
  • name string - The name of cookie to remove.

Returns Promise<void> - A promise which resolves when the cookie has been removed

Removes the cookies matching url and name


Returns Promise<void> - A promise which resolves when the cookie store has been flushed

Writes any unwritten cookies data to disk.