Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cookie support broken in Electron 5.0.x? #18220

Closed
3 tasks done
danawoodman opened this issue May 9, 2019 · 4 comments
Closed
3 tasks done

Cookie support broken in Electron 5.0.x? #18220

danawoodman opened this issue May 9, 2019 · 4 comments

Comments

@danawoodman
Copy link
Contributor

danawoodman commented May 9, 2019

Preflight Checklist

  • I have read the Contributing Guidelines for this project.
  • I agree to follow the Code of Conduct that this project adheres to.
  • I have searched the issue tracker for an issue that matches the one I want to file, without success.

Issue Details

  • Electron Version: 5.0.1
  • Operating System: mac OSX 10.14.4
  • Last Known Working Electron version:: 4.x

Expected Behavior

I should be able to set/remove a cookie.

Actual Behavior

I cannot set or remove a cookie

To Reproduce

import { session } from 'electron'

async function testCookies() {
  if (!session || !session.defaultSession)
    throw new Error('Could not get default user session')

  const cookies = session.defaultSession.cookies
  const name = 'foo'
  const url = '/'

  await cookies.set({
    url,
    name,
    value: 'Hello World!',
    expirationDate: 99999999.0,
  })

  console.log('COOKIES BEFORE:', await cookies.get({}))

  await cookies.remove(url, name)

  console.log('COOKIES AFTER:', await cookies.get({}))
}

//....
app.on('ready', () => {
  testCookies()
})

Additional Information

Running this on a Mac and have tried many permutations of the above but can't get anything to work. Things seemed to work in 4.x

@grantcv1
Copy link

grantcv1 commented May 10, 2019

I seem to be having similar problems with localStorage. It's now cleared between sessions -- but only in a packaged app. Works fine in dev.

My problem with LocalStorage is being caused by a stale LOCK file that is left behind when an application is quit (using app.quit()). Apparently, internal state data is transferred to a LevelDB database on quit, but the lock file on the database isn't properly cleaned up.

@afro-cloud
Copy link

@danawoodman & @grantcv1 either of you guys want to take this on? If not I'll grab it :)

@erickzhao
Copy link
Member

Heya @danawoodman,

@deermichel and I investigated further into this issue, but couldn't find anything wrong with cookie support in v5.0.3

Here's a link to a gist you can paste into Electron Fiddle. This contains a minimum working example for the Cookies API (also available under Show Me -> Electron APIs -> Cookies in the Fiddle menu bar).

Please let us know if the below comments don't solve your issue.


After some investigation, there seems to be a problem in the parameters from your posted example: the expirationDate option uses Unix epoch time, so expirationDate: 99999999.0 would tell your cookie to expire on Saturday, March 3, 1973. This would instantly delete it.


Also, setting url: '/' as an option leads to silent failure in Electron < 6. It should be rejecting the promise instead of resolving it, as the cookie domain associated to the URL is invalid. In this case, the invalid cookie will be unable to be filtered using the cookie.get({ url }) nor removed using cookie.remove({ url }).

This is a bug on Electron's end, and a fix was proposed in #18756 to prevent invalid cookies from being generated for Electron <=5. This problem has been fixed already as of the Electron 6 beta, as the cookie error handling logic was improved.


Putting it all together, here is a working gist for Electron Fiddle with some modifications to your original code.

@codebytere
Copy link
Member

Closing as a result of @erickzhao's and @deermichel's investigation above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
5.0.x
Unsorted Issues
Development

No branches or pull requests

7 participants