遇到Google Api时如何解决“空响应”和“跨域读取阻止(CORB)阻止跨源响应”警告

时间:2019-04-26 15:38:56

标签: javascript google-chrome-extension google-api cors cross-origin-read-blocking

我正在使用一个google chrome扩展程序,该扩展程序可以在youtube.com网站上工作,以显示当前播放视频的统计信息。当我转到youtube.com时,会显示我的扩展程序。然后,我从youtube网址中提取当前的videoId。然后,我点击https://www.googleapis.com/youtube/v3/videos以获取有关视频的详细信息。但我收到此错误并没有响应

Cross-Origin Read Blocking (CORB) blocked cross-origin response 
https://www.googleapis.com/youtube/v3/videos?id=HWGoW9si3_w&part=snippet,statistics,contentDetails,status&key=AIzaSyCmEXhJDt2rGqLt2yLccbvjs9L5rgyX_QM 
with MIME type application/json. 
See https://www.chromestatus.com/feature/5629709824032768 for more details.

我从这里enter image description here阅读了有关该错误的信息。我找到了

Make sure these resources are served with a correct "Content-Type" response header from the list below, as well as a "X-Content-Type-Options: nosniff" response header.

但是我得到的响应头为空

axios({headers: {'Content-Type':'application/json'}, method:'get', url:`https://www.googleapis.com/youtube/v3/videos?id=${videoId}&part=snippet,statistics,contentDetails,status&key=APIKey`})
        .then(function (response) {
          // handle success
          console.log("headers",response.headers);
        })

但是当我在POSTMAN中使用相同的API时,它工作正常,并且我获得了所有数据和这些标头(我同时拥有content-type,x-content-type-options)

alt-svc →quic=":443"; ma=2592000; v="46,44,43,39"
cache-control →private, max-age=120, must-revalidate, no-transform
content-encoding →gzip
content-length →8093
content-type →application/json; charset=UTF-8
date →Fri, 26 Apr 2019 13:35:23 GMT
etag →"XpPGQXPnxQJhLgs6enD_n8JR4Qk/ZtF3Y3gpsc5Lf1EwBdgxvPd3uuU"
expires →Fri, 26 Apr 2019 13:35:23 GMT
server →GSE
status →200
vary →Origin, X-Origin
x-content-type-options →nosniff
x-frame-options →SAMEORIGIN
x-xss-protection →1; mode=block

在研究此问题时,我发现大多数人建议我需要从服务器端更改响应头。但是我正在使用googleapis。所以我认为这对我来说是不可能的。

如何解决警告和空响应的问题?

0 个答案:

没有答案