chrome Extension : Set persistent cookie in chrome extension?

前端 未结 2 1437
囚心锁ツ
囚心锁ツ 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:53

    If you don't set a value for expirationDate then the cookie will expire when the user closes the browser.

    If you do set a value then it must be the current time + how many seconds until it expires. For example:

    {expirationDate: (new Date().getTime()/1000) + 3600}
    

    would set it as the current time, plus 3600 seconds, so an hour in the future.

    You were setting it as 3600 past the base UNIX time, which is the start of 1970, so it immediately expired.

提交回复
热议问题