作为学习使用 Google Auth 的一部分,我发现 fetch("https://accounts.google.com/gsi/client") 会导致
Access to script at 'https://accounts.google.com/gsi/client' from origin 'http://localhost:8080' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
标头应包含 access-control-allow-origin: * 就像获取时一样 https://apis.google.com/js/api.js
响应标头不包含 Access-Control-Allow-Origin 标头
在 devtools 的控制台或脚本中运行 fetch("https://accounts.google.com/gsi/client")
我发现我为
crossorigin="anonymous"
标签设置了 script
。
所以,如果我不使用 CORS,一切都会正常。