嗨,我很抱歉问这个问题,我做了很多研究,但我无法解决这个问题,我无法获取我的 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)