google-chrome - Chrome 扩展:未经检查的 runtime.lastError:无法解析或设置名为“ASP.NET_SessionId”的 cookie
问题描述
我开发了一个 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 密钥始终相同。
请参阅下面的代码。我已经替换了这个例子的网址。
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 拒绝任何带有前导点的网址
https://.example.com/
,例如. - url应该与secure匹配。这意味着,只要secure为真,url就应该以http s开头。
推荐阅读
- mysql - 从具有不同信息的 3 个表中获取数据
- reactjs - React 功能组件状态变化不会触发子组件重新读取其 props
- php - 根据PHP更改所有页面上的链接
- swift - AppStore 查看崩溃日志
- cassandra - 我可以将计数器类型字段用作 C* 表的主键吗?
- r - 如何解决错误:无法在 RStudio 中分配大小为 70.7 Gb 的向量?
- python-3.x - ITM(爱尔兰横坐标)转换为谷歌地图 Python3 的 GPS
- embedded - 在 Eclipse IDE 上使用带有 MBED 库的矢量偏移表
- gremlin - 如何使用 Gremlin 查询获取特定标签的源顶点和目标顶点之间的所有传入中间顶点的列表?
- javascript - 尽管使用了等待,但异步函数返回待处理的承诺