Pracowałem nad rozszerzeniem przeglądarki Chrome. Gdy próbowałem podłączyć firebase do aplikacji internetowej na dwa możliwe sposoby, żaden z nich nie działa.
- korzystanie z "npm install firebase" Kiedy próbowałem wykonać to polecenie, aby zainstalować firebase w folderze mojego projektu i napisał fireConn.js plik wraz z konfiguracją, którą dostałem z projektu firebase, utworzonego w Internecie.
import {initializeApp} from 'firebase/app';
import {getFirestore} from 'firebase/firestore';
Błąd, który otrzymałem, jest
Uncaught TypeError: Failed to resolve module specifier "firebase/app". Relative references must start with either "/", "./", or "../".
- za pomocą https://www.gstatic.com/firebasejs/9.4.1/firebase-app.js adres url do połączenia z bazą danych firebase
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";
Ponieważ mój projekt jest rozszerzeniem chrome, mam plik manifest.json w następującym formacie:
{
"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'"
}
}
Błąd, którą otrzymałem:(coś poszło nie tak z 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.