insomnia: CURL code generation not working

Describe the bug “Generate Code” and “Copy as CURL” functionality not working

To Reproduce Steps to reproduce the behavior:

  1. Create request
  2. Click on “Generate Code” or “Copy as CURL”

Expected behavior Generated CURL code or CURL request in clipboard

Screenshots An error in developer tools console:

/opt/Insomnia/resources/app.asar/node_modules/tough-cookie/lib/cookie.js:941 Uncaught (in promise) TypeError: Cannot read property 'getTime' of null
    at Cookie.expiryTime (/opt/Insomnia/resources/app.asar/node_modules/tough-cookie/lib/cookie.js:941)
    at matchingCookie (/opt/Insomnia/resources/app.asar/node_modules/tough-cookie/lib/cookie.js:1175)
    at Array.filter (<anonymous>)
    at /opt/Insomnia/resources/app.asar/node_modules/tough-cookie/lib/cookie.js:1188
    at MemoryCookieStore.findCookies (/opt/Insomnia/resources/app.asar/node_modules/tough-cookie/lib/memstore.js:113)
    at CookieJar.getCookies (/opt/Insomnia/resources/app.asar/node_modules/tough-cookie/lib/cookie.js:1183)
    at CookieJar.getCookiesSync (/opt/Insomnia/resources/app.asar/node_modules/tough-cookie/lib/cookie.js:1452)
    at getRequestCookies (bundle.js:74505)
    at exportHarWithRenderedRequest (bundle.js:74493)
    at process._tickCallback (internal/process/next_tick.js:68)

Desktop (please complete the following information):

  • OS: Linux Mint 19.3 Tricia
  • Installation Method: deb package
  • App Version 2020.3.3 (though didn’t work on 2020.2.2 either)

Additional context

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 15 (11 by maintainers)

Most upvoted comments

I’ve started to work on this, but there is something weird in the cookies modal logic.

I’ve taken a record when I’ve created a cookie and played with the Expires attribute 2482-cookies-modal

As you can see, there is something wrong. I’ve found the cause in those lines: https://github.com/Kong/insomnia/blob/c73092e2947d3eaf059473086b178fa2fe117df0/packages/insomnia-app/app/ui/components/modals/cookie-modify-modal.js#L112-L117

When we are saving changes, the value in cookie.expires is "0" instead of 0. Therefore we are “generating” a date using new Date('0') which different than new Date(0) 🤯

We should fix that, but I’d like your thoughts on what format we want to use in the Expires input? I’m thinking about:

  1. using a number (epoch time): 1603396449844
  2. using the UTC string (which is the format described in the RFC if I read it correctly ): Thu, 22 Oct 2020 19:54:09 GMT
  3. using the ISO string: 2020-10-22T19:54:09.844Z

I would use the 3rd option, the ISO string, which seems to be the simpler. Indeed, I can’t convert the epoch time in my head, and we would need to update the day matching the new date using the UTC. 🤔

Of course, this format would be used only in the input field. We would then adapt it when we update the cookie.

@jrodalo Thanks! I can reproduce 🎉 🙇

@develohpanda I was thinking about updating the library. But first I would like to reproduce the error and I’ve not succeeded yet 😞

Yes, I’m using Insomnia Core 2020.4.1

Steps to reproduce it:

  1. Create a new request for http://localhost/test
  2. Create a new cookie with the same domain: localhost and leave Expires empty
  3. Try to use the Generate Code or Copy as Curl options on the request
  4. See the error in the console: Cannot read property 'getTime' of null

Manually setting Expires = 0 fixes it. In my case, the cookie was created automatically from server response, but think it’s easier to reproduce it this way.

@jrodalo works here too! 🦀

This could happen if you have a cookie for the same domain without an expire date. As a workaround you can edit the cookie and set expires = 0 (or any other value). That works for me 🙂

Not sure if Insomnia could do something on their side, otherwise looks like an issue in the tough-cookie library: https://github.com/salesforce/tough-cookie/blob/8834cbaae1f523ab9490c991479b2df4870e29d4/lib/cookie.js#L994-L1005