4

How can I open Chrome to specific URL with cookies already set?

I don't mean cookies from an older session, I want to set the cookie(s) myself, similar to cURL's --cookie option.

e.g. something like:

google-chrome --cookie="FOO=BAR" https://example.org

Except --cookie doesn't appear to exist.

To be clear, I want to open a browser tab programatically and then give control back to the user. The user should not have to click anything to set the cookie.

  • Could this project provide you with some insight as to how cookies can be programmatically managed? – simlev Jun 15 '18 at 8:19
  • @simlev No, I don't think so. That's a Chrome extension -- it has privileged access to the cookies. I want to set them externally... unless maybe I could boot Chrome into an extension or script where I can pass along the cookie to set. – mpen Jun 16 '18 at 16:59
  • What did you end up deciding? I have the exact same question! – HipsterZipster Jan 31 at 0:54
  • @HipsterZipster Nothing. I gave up :'( – mpen Jan 31 at 1:09
2
+50

As far as I know, Chrome does not have Command Line Switches for saving and loading cookies. You need third-party software for that.

Windows users can use the free Nirsof ChromeCookiesView which has a GUI interface but can also be used via the command line. To load cookies :

ChromeCookiesView.exe /CookiesFile "c:\temp\Chrome\cookies"

ChromeCookiesView can save cookies in various formats, but it is unclear what formats it can load (maybe all of them).

Otherwise, I can only recommend some Chrome extensions that can export and import cookies :

  • Hmm... I'm on Linux (Ubuntu). Wish ChromeCookiesView shared their source code, maybe I can hack whatever files Chrome uses to store the cookies... – mpen Jun 15 '18 at 21:30
  • 2
    If you're into programming, Chrome saves then in an SQLite database called "Cookies" containing a table called "cookies", and that's where all the extensions do their export/import. Their values might be encrypted if requested, so I hope yours aren't, but if they are then solutions exist and google for them. – harrymc Jun 16 '18 at 7:38
  • 1
    You could create an sqlite3 file of commands that will import the cookies into the target. On the source you can select the table manually and export it to a file. You then distribute the two files, script and export file, and could launch sqlite3 to process them. There might be some complications to solve on the way, but this seems doable (if sqlite3 is installed). – harrymc Jun 16 '18 at 8:40
  • I guess I'll try that then. Thanks for the tips! – mpen Jun 16 '18 at 17:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.