gpt4 book ai didi

javascript - chrome.cookies.getAll 返回一个空数组

转载 作者:行者123 更新时间:2023-11-29 23:20:48 32 4
gpt4 key购买 nike

我正在开发一个简单的 chrome 扩展程序,只需单击一下即可删除域中的所有 cookie,但由于某种原因,它无法正常工作。当我尝试从域中获取所有 cookie 时,它​​返回一个空数组。我究竟做错了什么?这是 js 脚本:

$("#fixTheCookiesButton").click(() => {
// delete the cookies
chrome.cookies.getAll({domain: "https://www.youtube.com"}, (cookies) => {
console.log("deleting " + cookies.length + " cookies")
for(var i = 0; i < cookies.length; i++){
console.log(i + " deleted")
chrome.cookies.remove({
url: "https://www.youtube.com" + cookies[i].path,
name: cookies[i].name
})
}

// some other stuff that isn't relevant here
}

这是我的 list :

{
"manifest_version": 2,
"name": "FixYT",
"version": "1.0",
"description": "Fixes that YT cookie bug with one click",
"browser_action": {
"default_title": "FixYT",
"default_popup": "popup.html"
},
"permissions": [
"cookies",
"https://www.youtube.com/",
"*://www.youtube.com/",
"tabs",
"*://*/"
]
}

我试过在互联网上四处寻找,但找不到任何解决方案。

最佳答案

你应该在background.js中调用这个代码块

    chrome.cookies.getAll({
domain: ".youtube.com"
}, function (cookies) {
for (var i = 0; i < cookies.length; i++) {
console.log(cookies[i] + "deleted");
chrome.cookies.remove({
url: "https://" + cookies[i].domain + cookies[i].path,
name: cookies[i].name
});
}
});

关于javascript - chrome.cookies.getAll 返回一个空数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50771902/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com