ServiceWorker刷新时无法加载CSP异常的Google字体

问题描述

我将CSP设置为允许连接到Google字体服务,如下所示。第一次加载时,一切工作正常(我怀疑SW是否会缓存任何东西),但是当我刷新页面时,尽管看到connect-src明确添加了Google字体网址,但仍然看到错误

CSP已添加index.html

<Meta http-equiv="Content-Security-Policy"
          content="
                default-src 'self' https: fonts.googleapis.com;
                font-src 'self' https: fonts.googleapis.com fonts.gstatic.com data:;
                style-src 'self' 'unsafe-inline' https: fonts.googleapis.com fonts.gstatic.com data:;
                child-src 'self' fonts.googleapis.com;
                connect-src 'self' https: fonts.googleapis.com;
                object-src 'none';">

ngsw-config

     "assetGroups": [
        {
            "name": "app","installMode": "prefetch","resources": {
                "files": [
                    "/favicon.ico","/index.html","/manifest.webmanifest","/*.css","/*.js"
                ],"urls": [
                    "https://fonts.googleapis.com/**","https://fonts.gstatic.com/**"
                ]
            }
        }

错误

enter image description here

解决方法

好像您将CSP添加到错误的*.exe,而不是角度配置中添加了CSP。

在您的CSP中显示index.html,但根据控制台警告,default-src 'self' https: fonts.googleapis.com;...connect-src 'self' https: fonts.googleapis.com;发生了违规,并且由于缺少 connect-src 指令而被用作备用。

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...