我在 SSL 网站上成功转换谷歌广告,通过 rack-cors
正确设置了 CORS header (并且完全开放)作为:
Rails.configuration.middleware.insert_before 0, Rack::Cors do
allow do
origins '*'
resource '*', headers: :any, methods: :any
end
end
我可以通过 curl 调用确认 header 在那里:
$ curl -I https://viewing.nyc -H "Origin: https://foobar.com"
...
Access-Control-Allow-Origin: https://foobar.com
Access-Control-Allow-Methods: GET, HEAD, POST, PUT, PATCH, DELETE, OPTIONS
Access-Control-Max-Age: 1728000
...
如果您在 Chrome 或 Firefox 中访问,控制台中没有跨站点脚本错误,但在 Safari 上,有数千个。
Blocked a frame with origin "https://googleads.g.doubleclick.net" from accessing a frame with origin "https://viewing.nyc". Protocols, domains, and ports must match.
我已经浏览了 rack-cors
问题页面,到目前为止还没有解决方案。为什么这种情况仅在 Safari 上发生,我该如何解决?
最佳答案
我认为添加 content-security-policy header 应该对您有所帮助。
add_header Content-Security-Policy: script-src 'self' https://googleads.g.doubleclick.net
在这里阅读更多:-
https://developers.google.com/web/fundamentals/security/csp/
关于javascript - Safari 中的 Google Adsense、CORS 和 Rails 转储了数千个控制台错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40342649/