在 chrome 最近的 77.0 更新后,我开始在我的 chrome 扩展程序的后台页面上收到此警告。
A cookie associated with a cross-site resource at http://www.google.com/ was set without the
SameSite
attribute. A future release of Chrome will only deliver cookies with cross-site requests if they are set withSameSite=None
andSecure
. You can review cookies in developer tools under Application>Storage>Cookies and see more details at https://www.chromestatus.com/feature/5088147346030592 and https://www.chromestatus.com/feature/5633521622188032.
我能够通过设置将扩展恢复到之前的工作状态 SameSite 默认 cookie 为“已启用”。在 chrome://flags 上
当这个临时的客户端修复被禁用时,这段代码被执行,
console.log(rtLink)
rtLink 返回为未定义,启用客户端修复后,它会正确执行并显示从 google 搜索中找到的 url
//console.log("Background.js is running");
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
fetch(request)
.then(function(response) {
return response.text()
})
.then(function(html) {
var parser = new DOMParser();
var doc = parser.parseFromString(html, "text/html");
// Finds and sets the first search term URL to rtLink
var rtLink = doc.getElementsByClassName("r")[0].children[0].href;
console.log(rtLink);
我的问题是,我该如何设置 SameSite=Lax(或 None)和 Secure 我的获取请求/响应,或者我可能问错了问题。如果是这种情况,我必须具体更改哪些内容才能适应此 cookie 更改?
最佳答案
对于这些警告中的任何一个,如果您不对域负责,则您不负责更新 cookie。在这种情况下,Google 负责更新为来自 google.com
的 cookie 设置 SameSite
属性的相关代码。
此时,警告仅供引用,不会影响功能。直到 M80 才计划在稳定的 Chrome 中强制执行此行为,目前目标是 2020 年 2 月。
如果您希望 cookie 与您的 fetch
请求一起发送,您应该确保您是 explicitly including them .
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
fetch(request, { credentials: 'include' })
.then(function(response) { // snip
关于javascript - 设置 SameSite=none,在 Chrome 扩展中安全,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58441115/