首页 > 解决方案 > Chrome 扩展:未经检查的 runtime.lastError:无法解析或设置名为“ASP.NET_SessionId”的 cookie

问题描述

我开发了一个 Chrome 扩展程序,可以修改我工作场所使用的 ASP.net 系统的网页。

由于最近版本的 Chrome 中引入了新的 Cookie 限制,我必须删除 SameSite 宽松 cookie 并将其替换为 SameSite 无安全 cookie。

该组织最近将 Chrome 从 75 更新到了 80。现在它对某些人有效,对其他人则坏了。

尝试使用Chrome.cookiesapi 时,错误是Unchecked runtime.lastError: Failed to parse or set cookie named "ASP.NET_SessionId".

似乎每个人都在运行相同版本的 Chrome,并且 cookie 密钥始终相同。

请参阅下面的代码。我已经替换了这个例子的网址。

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
            })
        })
    })
}

标签: google-chromegoogle-chrome-extensionsamesite

解决方案


我得到了同样的错误。我通过遵循这些规则解决了它:

  1. url应该包含domain的值。您不能为url使用不同的域名。
  2. Chrome 拒绝任何带有前导点的网址https://.example.com/,例如.
  3. url应该与secure匹配。这意味着,只要secure为真,url就应该以http s开头。

推荐阅读