title: post instagram comment programmatically with js
body: <p>I'm creating an instagram bot that posts a comment on a user's photo. I'm aware there are already solutions like <a href="https://github.com/timgrossmann/InstaPy" rel="nofollow noreferrer">InstaPy</a> but it isn't working for me and I'm 99% complete with my own js solution.</p>
  
  <p>Is there a way for me to post programmatically? I already set the textArea.value and I tried to submit the wrapping form (it just refreshes the page). I also tried to "click" the submit button but it isn't causing it to do anything. I also tried to "type" into the textarea but it seems that isn't possible without any actual user interaction on the screen as well as trying to submit the actual request (seems my headers don't match up and I'm getting a 403 error.) Below is a code snippet of what I'm currently doing.</p>
  
  <pre><code>var commentTextArea = document.getElementsByClassName('Ypffh')[0];
  if (commentTextArea) {
  
      // Text area for posting comment
      commentTextArea.textContent = "This is my comment :)";
  
      setTimeout(function() {
  
          // Comment submit button
          var submitButton = document.getElementsByClassName('LCjcc')[0];
          submitButton.disabled = false;
          submitButton.click(); // doesn't fire anything. I can see in chrome dev tools there is no event event attached to this even when enabled which is odd
  
          // Comment form
          // Submitting form expectedly refreshes page
          // Tried add my own submit listener with return false &amp;&amp; e.preventDefault and neither worked
          var form = document.querySelector('X7cDz');
          if (form) {
  
              form.submit();
          }
      }, 2000);
  }
  </code></pre>