islalobo
islalobo

Reputation: 657

Cannot access session cookies in Electron app

We are building an electron application using v.4.1.4. Trying to access the browser window's webContents session cookies, but I am getting an empty object or undefined. The browser window is loading our web app's url and in this use case the user has logged in which sets a cookie (to our url). I can inspect the browser window and can see the cookies that exist, so I'm trying to understand why the following code isn't working:

  let win = new BrowserWindow({ dimensions });
  win.loadURL(ourUrl);
  const ses = win.webContents.session;
  console.log(win.webContents.session.cookies); <--- empty

I thought I could get the webContents session cookies, but perhaps I have to set a cookie when the user logs in.

Upvotes: 1

Views: 2188

Answers (1)

Josiah Ruddell
Josiah Ruddell

Reputation: 29831

The cookies.get API isn't very intuitive, try:

webContents.session.cookies.get({}, (err, cookies) => console.log(cookies))

Upvotes: 1

Related Questions