【问题标题】:Adsense sometimes doesn't serve ads because of Content Security Policy由于内容安全政策,Adsense 有时不会投放广告
【发布时间】:2021-04-28 02:08:59
【问题描述】:

我最近将 Google AdSense 添加到我的网站并且广告运行良好,但有时它们无法加载并且我在控制台中收到以下错误

Refused to execute inline script because it violates the following Content Security Policy directive: "script-src https://cdn.ampproject.org/". Either the 'unsafe-inline' keyword, a hash ('sha256-xxx'), or a nonce ('nonce-...') is required to enable inline execution.

根据我阅读的内容,我需要在我的 HTML 标头中添加 CSP,但似乎无法解决问题。

有什么建议吗?

【问题讨论】:

    标签: content-security-policy adsense


    【解决方案1】:

    TRY1

    discussion 可以通过以下 sn-p 帮助访问该站点:

    script-src 'self' http://xxxx 'unsafe-inline' 'unsafe-eval';
    

    TRY2

    documentation 将向您展示如何定义策略:

    Content-Security-Policy: script-src 'self' https://apis.google.com
    

    希望这会有所帮助,您的问题已得到解答。试一试,加油! :)

    【讨论】:

    • 我不推荐这里的第一个解决方案,它基本上消除了 CSP 的全部意义。第二种解决方案稍微好一点,它打开了来自 Google API 域的脚本。
    • 你完全正确! Try 1 被认为是首先让它运行。保留您的评论将有助于尝试 2。感谢您的贡献!
    猜你喜欢
    • 2023-02-02
    • 1970-01-01
    • 2019-04-15
    • 1970-01-01
    • 2015-07-22
    • 2016-10-03
    • 2017-04-24
    • 1970-01-01
    • 2020-12-29
    相关资源
    最近更新 更多