Google chrome extension 获取API、Chrome扩展、内容脚本、CORS权限

Google chrome extension 获取API、Chrome扩展、内容脚本、CORS权限,google-chrome-extension,fetch-api,Google Chrome Extension,Fetch Api,不知道是否有其他人注意到了这一点 在内容脚本中对图像文件执行XMLHttpRequest: var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { console.log(xhttp.getAllResponseHeaders()); } }; xhttp.o

不知道是否有其他人注意到了这一点

在内容脚本中对图像文件执行XMLHttpRequest:

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
        console.log(xhttp.getAllResponseHeaders());
    }
};
xhttp.open("HEAD", "https://www.gstatic.com/webp/gallery3/1.sm.png", true);
xhttp.send();
您将获得以下信息:

日期:2018年11月27日星期二15:42:53 GMT x-content-type-options:nosniff 最后修改:2016年4月21日星期四03:17:22 GMT服务器:sffe年龄:1136854 更改:源内容类型:图像/png状态:200缓存控制: public,max age=31536000接受范围:bytes alt svc:quic=“:443”; ma=2592000;v=“44,43,39,35”内容长度:48061 x-xss-protection:1; 模式=块过期时间:2019年11月27日星期三15:42:53 GMT

在内容脚本中对同一图像发出提取请求:

fetch("https://www.gstatic.com/webp/gallery3/1.sm.png", {method: "HEAD"})
    .then(res => { 
        var headers = res.headers;
        headers.forEach(function(value, name) { console.log(`${name} : ${value}`);
     });
您将获得以下信息:

缓存控制:公共,最大年龄=31536000内容类型:图像/png 到期时间:2019年12月10日星期二20:12:24 GMT上次修改时间:2016年4月21日星期四 03:17:22格林尼治标准时间

这是由于W3规范,它向我证实了fetch并没有完全受益于Chrome扩展的跨源清单豁免。但是,如果使用Fetch发出get请求,则会成功


有人知道这是否是故意的吗?

很可能是。无论如何,你应该在后台脚本中完成,因为这将是未来唯一的方法。谢谢你的链接,非常有趣。您对这些更改有何看法?在相关的crbug中没有太多要添加的注释。希望我们能够在他们真正开始实施设计后影响设计。顺便说一句,似乎要撤销我上面所说的。