chrome Extension : Set persistent cookie in chrome extension?

前端 未结 2 1434
囚心锁ツ
囚心锁ツ 2021-02-08 08:47

I am working with chrome extension development here I need to set cookie value by my extension.

I have set cookies by:

chrome.cookies.set({ url: "http         


        
2条回答
  •  北恋
    北恋 (楼主)
    2021-02-08 08:56

    It seems that your expiration date is 1 Jan 1970 01:00 (3600 equals 1 hour after UNIX epoch). So of course your cookie will be deleted because it's expiration date is set to the past.

    You need to provide appropriate expirationDate for your cookie. In documentation, expirationDate defined as:

    The expiration date of the cookie as the number of seconds since the UNIX epoch

    To set a cookie relative to the current time you need to add seconds to (new Date().getTime() / 1000) as @pickled suggested.

提交回复
热议问题