javascript - 特定于 Firefox - CORS 预检 channel 中的 CORS header ‘user-agent’ 中缺少 token ‘Access-Control-Allow-Headers’

标签 javascript google-maps firefox cors

我正在尝试对 googleMapsClient 地理编码进行 api 调用,但仅在使用 Firefox 时才收到 XHR 错误。它在 Chrome 中工作正常,但在 Firefox 中,我收到以下错误

>     Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at
> https://maps.googleapis.com/maps/api/geocode/json?address=Kothaguda%2C%20Hyderabad%2C%20Telangana%2C%20India&key=xxxx.
> (Reason: missing token ‘user-agent’ in CORS header
> ‘Access-Control-Allow-Headers’ from CORS preflight channel)

不知道为什么这是 Firefox 特有的。我可以看到请求中有一个“user-agent”http header 。非常感谢对此的任何帮助。

最佳答案

您使用的是 @google/maps 软件包吗?请注意,这个包应该只与node.js一起使用,而不是在浏览器中使用。 README中也有说明。 :

Attention! This library is designed for server-side Node.js applications. Attempting to use it client-side, in either the browser or any other environment like React Native, may in some cases work, but mostly will not. Please refrain from reporting issues with these environments when attempting to use them, since server-side Node.js applications is the only supported environment for this library. For other environments, try the Maps JavaScript API, which contains a comparable feauture set, and is explicitly intended for use with client-side JavaScript.

我建议使用 Google Maps JavaScript API。

关于javascript - 特定于 Firefox - CORS 预检 channel 中的 CORS header ‘user-agent’ 中缺少 token ‘Access-Control-Allow-Headers’,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53413174/

相关文章:

Javascript继承实现问题

javascript - 将 JavaScript Math.pow 用于 Excel 公式

javascript - 将 HTML 链接添加到 Google map 圆形元素

algorithm - 在给定纬度和经度的情况下找到最近的标记 map 地标/地点

Javascript 代码可以在 Mozilla Firefox 中运行,但不能在 Google Chrome 中运行

javascript - 如何使用rails自定义鼠标指针?

javascript - 确定 Google Maps API 是否在运行时使用了无效 key

javascript - nsICacheService 在 Firefox 38 中不起作用

Firefox 给出 "The certificate is not trusted"

java - struts 2 jquery 插件不工作