Create new cookie with host only set to false in chrome extension

21 Views Asked by At

On the current tab, I need to insert a cookie with host only set to false

I followed the below code but its set host only always to true

I belive its something to do with domain but how can I create a domain from any given URL to create host only set to false

For e.g https://developer.chrome.com/docs/extensions/reference/api/cookies

https://www.google.com

let cookieData = {
    name :cookieName,
    value: cookieValue,
    expiration: timeValue,
    httpOnly: httpValue,
    host: hostValue
   }

const insertNewCookie = async (cookieData) => {
    let [tab] = await chrome.tabs.query({ active: true, currentWindow: true })
    let newExpirationDate
    if(cookieData.expiration)
    {
        newExpirationDate = dayjs(cookieData.expiration).format("YYYY-MM-DD HH:mm:ss")
        newExpirationDate = moment(newExpirationDate).unix()
    }
    let updatedData = {
        "name": cookieData.name,
        "value": cookieData.value,
        "httpOnly": cookieData.httpOnly,
        "expirationDate": newExpirationDate,
        "url" : tab.url
    }
    await chrome.cookies.set(updatedData, function (cookie) {
    });
}
0

There are 0 best solutions below