Rob--W / cookie-manager

Cookie Manager for Firefox (Desktop/Android), Chrome. Supports viewing and editing of cookies and private cookies.
Mozilla Public License 2.0
105 stars 24 forks source link

consider adding feature to save/restore all cookies to a file #2

Closed 0c1 closed 6 years ago

Rob--W commented 7 years ago

Implementation note:

* pretty JSON = formatted JSON, i.e. NOT everything one one line, so that users can edit the file by hand if wanted.

Jon-Dijk commented 6 years ago

Hello

With the recent update of Firefox to version 57 all cookie managers that support importing and exporting all cookies (not from one tab only) to Netscape format file (as used by wget) stopped working and they probably will not be updated.

The best usability had Advanced Cookie Manager https://addons.mozilla.org/en-US/firefox/addon/cookie-manager/ - one click on the icon on the Toolbar, "Import All Cookies" or "Export All Cookies", choose a text file name, done.

I would love a similar functionality in your Cookie Manager.

Thank you and best regards. JD

Rob--W commented 6 years ago

Is there a specific format that you'd like to see? I could easily serialize all known cookies as JSON and then offer to import that, but if there is already an established format it can make more sense to implement that.

Jon-Dijk commented 6 years ago

I think the best format for this purpose is Netscape's cookies.txt file format like this because it is used by curl, wget and many other useful tools. JSON files would need to be converted afterwards, at least for my purposes.

Also I think it would make sense to display all cookies by default, because currently you have to manually type * and press enter to see them, which is tedious when you have dozens of cookie sets to test.

Rob--W commented 6 years ago

I think the best format for this purpose is Netscape's cookies.txt file format like this because it is used by curl, wget and many other useful tools. JSON files would need to be converted afterwards, at least for my purposes.

This format is too limited; it does not support things like HTTP-only, incognito flag, first-party-domain flag, and other browser-specific values.

Also I think it would make sense to display all cookies by default, because currently you have to manually type * and press enter to see them, which is tedious when you have dozens of cookie sets to test.

All cookies are displayed by default if you click on the search button.

Jon-Dijk commented 6 years ago

This is true, but it's still used in a wide range of tools.

Anyway, it's better to have an option to Import All/Export All to JSON than not to have it at all, which is the situation Mozilla has put us.

Thanks

0c1 commented 6 years ago

A simple export/import of all cookies would handle my needs.

Lekensteyn commented 6 years ago

Suggestion: add two output formats:

Suggested UI:

[ Import / Export | v ]
Export as Netscape HTTP cookie file
Export preserving all (metadata)
Import

Export as above, offering a file dialog (let's not complicate with a textarea?) Import is easy, if it starts with { (or [ depending on specification choice, and possibly skipping whitespace and Unicode BOM), consider it the "full" format. Otherwise consider it the Netscape HTTP cookie file.

Regarding http-only, maybe apply curl's standard?

$ curl --cookie-jar cookies.txt https://github.com -i
...
Set-Cookie: logged_in=no; domain=.github.com; path=/; expires=Wed, 02 Dec 2037 18:54:25 -0000; secure; HttpOnly                                                                                                                                                              
Set-Cookie: _gh_sess=...; path=/; secure; HttpOnly                                                                                                                                                                                                                                                           
...

cookies.txt:

# Netscape HTTP Cookie File
# https://curl.haxx.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.

#HttpOnly_.github.com   TRUE    /       TRUE    2143392865      logged_in       no
#HttpOnly_github.com    FALSE   /       TRUE    0       _gh_sess        ...
Rob--W commented 6 years ago

I added import/export as JSON. Documentation needs to be done, but I think that it is self-explanatory.

Other formats can be added in the future. I would also like to add the ability to first inspect cookies before importing them, but I decided to defer that to a future release. The code is already structured in a way that it can reasonably easily be supported (in fact for testing I already simulate a fake cookie database, and that works fine.)

Jon-Dijk commented 6 years ago

Thank you. I still would love to see importing/exporting cookies in the Netscape cookies.txt format, but still, this is a great leap forward.

0c1 commented 6 years ago

Thank you, The import/export of all cookies is what I need. It's working. Should I be the one to close the issue and if so, is it time to close it?

Rob--W commented 6 years ago

The feature itself has been implemented. While there are still opportunities for improvements, I think that this issue can be closed.

For the outstanding tasks, I have created new issues (e.g. #4 for @Jon-Dijk's request to use the Netscape format).