我开发了一个 Chrome 扩展程序,可以修改我工作场所使用的 ASP.net 系统的网页。
由于最新版本的 Chrome 中引入了新的 Cookie 限制,我必须删除 SameSite 松散 cookie 并将其替换为 SameSite 无安全 cookie。
该组织最近将 Chrome 从 75 更新到 80。现在它适用于某些人,但对其他人来说却无法使用。
当尝试使用 Chrome.cookies
api 时,错误是 Unchecked runtime.lastError: Failed to parse or set cookie named "ASP.NET_SessionId"
。
似乎每个人都在运行相同版本的 Chrome,并且 cookie key 始终相同。
请参阅下面的代码。我已替换此示例的网址。
function sameSiteCookieMaker() {
chrome.cookies.get({
"url": "https://example.example.example.com.au",
"name": "ASP.NET_SessionId"
}, function(cookie) {
state = cookie.value
chrome.cookies.remove({
"url": "https://example.example.example.com.au",
"name": "ASP.NET_SessionId"
}, function(cookie2) {
chrome.cookies.set({
"url": "https://example.example.example.com.au",
"domain": "example.example.example.com.au",
"httpOnly": true,
"name": "ASP.NET_SessionId",
"path": "/",
"sameSite": "no_restriction",
"secure": true,
"storeId": "0",
"value": state
})
})
})
}
最佳答案
我遇到了同样的错误。我按照这些规则解决了它:
- url 应包含 domain 的值。您不能为 url 使用不同的域名。
- Chrome 拒绝任何带有前导点的 url,例如
https://.example.com/
。 - url 应与 secure 匹配。这意味着,只要 secure 为真,url 就应该以 https 开头。
关于google-chrome - Chrome 扩展 : Unchecked runtime. lastError:无法解析或设置名为 "ASP.NET_SessionId"的 cookie,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60699502/