Senaryoyu yüklemeyi reddetti 'https://www.gstatic.com/firebasejs/9.4.1/firebase-app.js' çünkü aşağıdaki İçerik Güvenliği Politikasını ihlal ediyor

0

Soru

Bir chrome tarayıcı uzantısı üzerinde çalışıyordum. Firebase'i web uygulamasına 2 olası yolla bağlamaya çalıştığımda hiçbiri çalışmıyor.

  1. "npm firebase'i yükle" yi kullanma Firebase'i proje klasörüme yüklemek için bu komutu denedim ve bir fireConn yazdım.js dosyası, çevrimiçi olarak oluşturulan firebase projesinden aldığım yapılandırmayla birlikte.
import {initializeApp} from 'firebase/app';
import {getFirestore} from 'firebase/firestore';

Var olan hatadır

Uncaught TypeError: Failed to resolve module specifier "firebase/app". Relative references must start with either "/", "./", or "../".
  1. kullanarak https://www.gstatic.com/firebasejs/9.4.1/firebase-app.js firebase ile bağlantı kurmak için 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";

Projem bir chrome uzantısı olduğundan, bir bildirimim var.aşağıdaki biçimde olan json dosyası:

{
  "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'"
  }
}

Aldığım hata şudur: (content_security_policy ile bir şeyler ters gitti)

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

En iyi cevabı

0

İlk olarak, içe aktarmaları aşağıdaki gibi değiştirin:

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";

Bununla ilgili daha fazla bilgiyi belgelerden bulabilirsiniz. Bir modül paketleyicisi kullandığınızdan, eklenecek type="module" gerekir. Doğru format şöyle olmalıdır:

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

Lütfen dikkat: src, yolu nasıl ayarladığınıza bağlıdır.

Web-Firebase Temelleri için Firebase ile başlarken videosuna da başvurabilirsiniz. Ayrıca, Firebase'e bağlanılamıyor, Firebase'deki Yakalanmamış Hata buna eklenebilir.

2021-11-22 09:28:05

Diğer dillerde

Bu sayfa diğer dillerde

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