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.
- "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 "../".
- 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.