I have a Javascript Web application. I trying to read or write to the Cloud Firestore database but it returns this error in the browser console.
THE ERROR:
Failed to load https://firestore.googleapis.com/google.firestore.v1beta1.Firestore/Write/channel?VER=8&RID=21505&CVER=21&X-HTTP-Session-Id=gsessionid&%24httpHeaders=X-Goog-Api-Client%3Agl-js%2F%20fire%2F4.8.2%0D%0Agoogle-cloud-resource-prefix%3Aprojects%2FProjectName%2Fdatabases%2F(default)%0D%0A&zx=v9xcdtq156tr&t=1:
The 'Access-Control-Allow-Origin' header has a value 'null' that is not equal to the supplied origin. Origin 'null' is therefore not allowed access.
The Security Rules were set to Public read/write
service cloud.firestore {
match /databases/{database}/documents {
match /{document=**} {
allow read, write;
}
}
}
Here is my test code
<script src="https://www.gstatic.com/firebasejs/4.11.0/firebase.js"></script>
<script src="https://www.gstatic.com/firebasejs/4.11.0/firebase-firestore.js"></script>
<script>
var config = {
apiKey: "XXXXXXXXXXX",
authDomain: "XXXXXXXXXXXX",
databaseURL: "XXXXXXXXXXXX",
projectId: "XXXXXXXXXXXX",
storageBucket: "XXXXXXXXXXXX",
messagingSenderId: "XXXXXXXXXXXX"
};
firebase.initializeApp(config);
// Firebase Variables
var db = firebase.firestore();
db.collection("cities").doc("LA").set({
name: "Los Angeles",
state: "CA",
country: "USA"
}).then(function () {
console.log("Document successfully written!");
}).catch(function (error) {
console.error("Error writing document: ", error);
});
</script>
Google Chrome Version 65.0.3325.162 is the problem. Tested with Microsoft Edge and it worked
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With