Bug 220118 - Web Inspector: Copy cookie as Netscape HTTP Cookie File format
Summary: Web Inspector: Copy cookie as Netscape HTTP Cookie File format
Status: NEW
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Inspector (show other bugs)
Version: Safari 14
Hardware: All All
: P2 Enhancement
Assignee: Nobody
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2020-12-23 07:10 PST by Ryan Govostes
Modified: 2020-12-30 07:11 PST (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ryan Govostes 2020-12-23 07:10:18 PST
`curl` and other tools can read cookies from a cookies.txt file in Netscape HTTP Cookie File format.

It would be great if copying a cookie from the Storage tab of the Inspector used this format.

There is some documentation on this format here: https://curl.se/docs/http-cookies.html
Comment 1 Ryan Govostes 2020-12-23 07:37:43 PST
Probably a bad attempt at a function to convert the tabular format that gets copied now to the cookies.txt format. Assumes the column visibility and ordering settings (which I think are default).

(function (cookies) {
    return "# Netscape HTTP Cookie File\n" + cookies.split("\n").map( (cookie) => {
        let [name, value, domain, path, expires, size, secure, httponly, samesite] = cookie.split("\t")
        expires = Date.parse(expires) / 1000
        return domain + "\t" + (!!samesite ? "FALSE" : "TRUE") + "\t" + path + "\t" + (!!secure ? "FALSE" : "TRUE") + "\t" + expires + "\t" + name + "\t" + value
    }).join("\n")
})(the_cookies)
Comment 2 Radar WebKit Bug Importer 2020-12-30 07:11:12 PST
<rdar://problem/72739425>