拒绝装载的脚本https://www.gstatic.com/firebasejs/9.4.1/firebase-app.js'因为它违反了以下内容的安全政策

0

的问题

我正在浏览器扩展。 当我试图连接火力地堡的网络应用程序,在2个可能的方式没有工作。

  1. 使用"故宫安装火力地堡" 当我试图这个命令要安装火力地堡进入我的项目文件夹写了fireConn.js 文件随着配置我从火力地堡的项目创建在线。
import {initializeApp} from 'firebase/app';
import {getFirestore} from 'firebase/firestore';

错,我得到的是

Uncaught TypeError: Failed to resolve module specifier "firebase/app". Relative references must start with either "/", "./", or "../".
  1. 使用 https://www.gstatic.com/firebasejs/9.4.1/firebase-app.js url获得连接的火力地堡
import {initializeApp} from "https://www.gstatic.com/firebasejs/9.4.1/firebase-app.js";
import {getFirestore} from "https://www.gstatic.com/firebasejs/9.4.1/firebase-firestore.js";

因为我的项目是一款名,我有一个清单。json文件,该文件是在以下格式:

{
  "name": "xxx",
  "manifest_version": 3,
  "version": "1.0",
  "permissions": ["cookies","tabs"],
  "host_permissions": ["<all_urls>"],
  "action": {
    "default_popup": "popup.html"
  },
  "content_security_policy": {
    "extension_pages": "script-src 'self'; object-src 'self'",
    "sandbox": "sandbox allow-scripts; script-src 'self' 'https://apis.google.com/' 'https://www.gstatic.com/' 'https://*.firebaseio.com' 'https://www.googleapis.com' 'https://ajax.googleapis.com'; object-src 'self'"
  }
}

错,我得到的是:(一些东西错了与content_security_policy)

Refused to load the script 'https://www.gstatic.com/firebasejs/9.4.1/firebase-firestore.js' because it violates the following Content Security Policy directive: "script-src 'self'". Note that 'script-src-elem' was not explicitly set, so 'script-src' is used as a fallback.
1

最好的答案

0

第一,修改进口如下:

import { initializeApp } from "https://www.gstatic.com/firebasejs/9.4.1/firebase-app.js";
import { getFirestore, collection, getDocs } from "https://www.gstatic.com/firebasejs/9.4.1/firebase-firestore.js";

你可以找到更多的信息,有关它的 文件. 因为你都是用一个模块,用,需要type="模块"可以加入它。 正确的格式应该是:

<script type="module" src="........”></script>

请注意:src取决于你如何设置的路径。

你也可以参阅视频 开始使用火力地堡的网络的火力地堡的基础. 此外, 无法连接到火力地堡,未捕获的错误在火力地堡 可能会增加。

2021-11-22 09:28:05

其他语言

此页面有其他语言版本

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................