Pracoval jsem na chrome rozšíření prohlížeče. Když jsem se pokusil připojit firebase s web app v 2 možné způsoby, nic se pracuje.
- pomocí "npm install firebase" Když jsem se snažil tento příkaz k instalaci firebase do složky projektu a napsal fireConn.js soubor spolu s konfiguraci jsem dostal od firebase projekt vytvořený on-line.
import {initializeApp} from 'firebase/app';
import {getFirestore} from 'firebase/firestore';
Chyby, které jsem dostal, je
Uncaught TypeError: Failed to resolve module specifier "firebase/app". Relative references must start with either "/", "./", or "../".
- pomocí https://www.gstatic.com/firebasejs/9.4.1/firebase-app.js url se připojit s 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";
Jako moje projektu je rozšíření pro chrome, mám projevovat.json souboru, který je v následujícím formátu:
{
"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'"
}
}
Chyba, které jsem se dostat je:(něco se pokazilo s 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.