title: Triggering Synthetic Event in React App
body: <p>I'm writing a Chrome extension for Facebook and want to programmatically trigger the submission of the focused comment draft on a post. The default behavior is to submit when the user hits the Enter key, so I'm attempting to trick the Facebook UI into thinking that the user did so.</p>
  
  <p>Facebook uses React and a <code>contenteditable</code> div for comment forms.</p>
  
  <p>Here's a set of things that I've tried:</p>
  
  <p>1) jQuery Event triggering <code>$('&lt;the contenteditable div&gt;').trigger($.Event('keydown', {which: 13}))</code></p>
  
  <ul>
  <li>I've tried this from both the content-script environment and the actual page environment (via both an injected script that responds to <code>postMessage</code> and the Chrome console)</li>
  <li>I've also tried triggering the event on the <code>document</code>, from each context.</li>
  <li>Nothing seems to happen.</li>
  </ul>
  
  <p>2) Same thing, but with VanillaJS event triggering. <a href="https://stackoverflow.com/questions/596481/simulate-javascript-key-events">relevant StackOverflow question</a></p>
  
  <ul>
  <li>also from both environments</li>
  <li>Nothing happens</li>
  </ul>
  
  <p>3) At this point I realized that this is React and it uses it's own <code>SyntheticEvents</code>, so I basically copy/pasted the <a href="https://github.com/facebook/react/blob/master/src/test/ReactTestUtils.js?source=c#L436" rel="nofollow noreferrer"><code>Simulate</code> function from <code>ReactTestUtils</code></a> that's supposed to help testing by simulating events and ran that within the page's environment (grabbing references to the <code>required</code> objects via Facebook's frontend <code>require</code> function).</p>
  
  <ul>
  <li>Also does not work. The function executes fully and without errors, but there's no response from the application.</li>
  </ul>
  
  <p>I've tried this with mostly <code>keydown</code> events, because that has the most listeners attached to it.</p>
  
  <p>I'm aware of these questions, but they haven't helped my understanding: <a href="https://stackoverflow.com/questions/30145747/force-react-to-fire-event-through-injected-javascript">Force React to fire event through injected JavaScript</a></p>