小编pti*_*ste的帖子

Chrome扩展/cookie/等待回调函数

嗨,我很抱歉问这个问题,我做了很多研究,但我无法解决这个问题,我无法获取我的 cookie 的值,我认为这是因为我的函数有一个回调,(我在我的代码)但我不知道修复它:/

const cookieUrl = 'http://urlCookie'
const cookieName = 'CookieName'

cookieValue = checkCookie(cookieUrl,cookieName)
console.log('cookieValue: ', cookieValue)

function checkCookie(url, name){
    chrome.cookies.get({
        url: url,
        name: name
    },
    function (cookie) {
        if (cookie) {
        console.log(cookie.value)
        return cookie.value
        }
        else {
        console.log('Can\'t get cookie! Check the name!')
        return 0
        }
    })
}
Run Code Online (Sandbox Code Playgroud)

javascript cookies google-chrome-extension async-await

2
推荐指数
1
解决办法
1853
查看次数