Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read/Write Error with Cloud Firestore: The 'Access-Control-Allow-Origin' header has a value 'null'

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>
like image 347
Crystal Avatar asked Dec 24 '22 08:12

Crystal


1 Answers

Google Chrome Version 65.0.3325.162 is the problem. Tested with Microsoft Edge and it worked

like image 187
Crystal Avatar answered Feb 10 '23 08:02

Crystal