formatCookie can be called with cookie objects created by the tough-cookie's Cookie.parse method or by directly passing cookies in DevTools Protocol format. When cookies are in DevTools format, the expiration field is in seconds from the unix epoch, whereas dayjs interprets numeric inputs as milliseconds from the unix epoch. So, if this field is a number, it needs to be multiplied by 1000 before being passed to dayjs. Currently, cookies from DevTools format all appear to expire in the 1970s.
A minimalist fix might be (though I haven't tested it):
I discovered the issue while experimenting with porting/re-writing chrome-har in typescript and trying to replicate chrome-har's current behavior. Please feel free to compare against the typescript implementation to test the fix, or to adopt the code from it, which is also MIT license. (You're free to take the whole thing, but it's a very big change of coding style to adapt to if you don't like typescript.) Sorry that the first you are hearing from me is me filing bugs, but leaving them unreported seemed worse than the alternative.
https://github.com/sitespeedio/chrome-har/blob/5b076f8c8e578e929670761dcc31345e4e87103c/lib/cookies.js#L13
formatCookie
can be called with cookie objects created by thetough-cookie
'sCookie.parse
method or by directly passing cookies in DevTools Protocol format. When cookies are in DevTools format, the expiration field is in seconds from the unix epoch, whereasdayjs
interprets numeric inputs as milliseconds from the unix epoch. So, if this field is a number, it needs to be multiplied by 1000 before being passed todayjs
. Currently, cookies from DevTools format all appear to expire in the 1970s.A minimalist fix might be (though I haven't tested it):
I discovered the issue while experimenting with porting/re-writing
chrome-har
in typescript and trying to replicatechrome-har
's current behavior. Please feel free to compare against the typescript implementation to test the fix, or to adopt the code from it, which is also MIT license. (You're free to take the whole thing, but it's a very big change of coding style to adapt to if you don't like typescript.) Sorry that the first you are hearing from me is me filing bugs, but leaving them unreported seemed worse than the alternative.