title: Difficulties with CORS access and writing data into firebase firestore
body: <p>I am trying to use firestore (which is new for me) in javascript but I am facing a CORS error and I am a little bit stucked. I just want my js code to send data from input to firebase firestore. But CORS access isn't allowing me to do this. And no data is written in the firebase firestore. There are only CORS errors in the console. I would be glad if anyone helps me with this issue</p>
  <pre class="lang-html prettyprint-override"><code>&lt;form id=&quot;contactForm&quot; action=&quot;#&quot; class=&quot;bg-light p-4 p-md-5 contact-form&quot;&gt;
    &lt;div class=&quot;form-group&quot;&gt;
      &lt;input type=&quot;text&quot; id=&quot;name&quot; class=&quot;form-control&quot; placeholder=&quot;Your Name&quot;&gt;
    &lt;/div&gt;
    &lt;div class=&quot;form-group&quot;&gt;
      &lt;input type=&quot;text&quot; id=&quot;email&quot; class=&quot;form-control&quot; placeholder=&quot;Your Email&quot;&gt;
    &lt;/div&gt;
    &lt;div class=&quot;form-group&quot;&gt;
      &lt;input type=&quot;text&quot; id=&quot;subject&quot; class=&quot;form-control&quot; placeholder=&quot;Subject&quot;&gt;
    &lt;/div&gt;
    &lt;div class=&quot;form-group&quot;&gt;
      &lt;textarea name=&quot;&quot; id=&quot;message&quot; cols=&quot;30&quot; rows=&quot;7&quot; class=&quot;form-control&quot; placeholder=&quot;Message&quot;&gt;&lt;/textarea&gt;
    &lt;/div&gt;
    &lt;div class=&quot;form-group&quot;&gt;
      &lt;input type=&quot;submit&quot; onclick=&quot;writeData()&quot; value=&quot;Send Message&quot; class=&quot;btn btn-primary py-3 px-5&quot;&gt;
    &lt;/div&gt;
  &lt;/form&gt;
  
  &lt;script src=&quot;https://www.gstatic.com/firebasejs/7.16.0/firebase-app.js&quot;&gt;&lt;/script&gt;
  &lt;script src=&quot;https://www.gstatic.com/firebasejs/7.16.0/firebase-analytics.js&quot;&gt;&lt;/script&gt;
  &lt;script src=&quot;https://www.gstatic.com/firebasejs/7.16.0/firebase-firestore.js&quot;&gt;&lt;/script&gt;
  &lt;script src=&quot;https://www.gstatic.com/firebasejs/7.16.0/firebase-storage.js&quot;&gt;&lt;/script&gt;
  
  &lt;script&gt;
    var firebaseConfig = {
      apiKey: &quot;XXXXXXXXXXXXXXXXXXXXX&quot;,
      authDomain: &quot;XXXXXXXXXXXXXXXXXXXXX&quot;,
      databaseURL: &quot;XXXXXXXXXXXXXXXXXXXXX&quot;,
      projectId: &quot;XXXXXXXXXXXXXXXXXXXXX&quot;,
      storageBucket: &quot;XXXXXXXXXXXXXXXXXXXXX&quot;,
      messagingSenderId: &quot;XXXXXXXXXXXXXXXXXXXXX&quot;,
      appId: &quot;XXXXXXXXXXXXXXXXXXXXX&quot;,
      measurementId: &quot;XXXXXXXXXXXXXXXXXXXXX&quot;
    };
    firebase.initializeApp(firebaseConfig);
    // Initialize Firebase
  
    firebase.analytics();
  
  
    var db = firebase.firestore();
  
    function writeData() {
      let name = document.getElementById(&quot;name&quot;).value;
      let email = document.getElementById(&quot;email&quot;).value;
      let subject = document.getElementById(&quot;subject&quot;).value;
      let message = document.getElementById(&quot;message&quot;).value;
  
  
      db.collection(&quot;FormMessage&quot;).set({
          name: name,
          email: email,
          subject: subject,
          message: message
        })
        .then(function () {
          console.log(&quot;Document successfully written!&quot;);
        })
        .catch(function (error) {
          console.error(&quot;Error writing document: &quot;, error);
        });
  
    }
  &lt;/script&gt;
  </code></pre>