title: How to to initialize keyboard event with given char/keycode in a Chrome extension?
body: <p>I'm developing a Google Chrome extension which simulates keyboard events on a web-page.</p>
  
  <p>I found that <code>event.initKeyboardEvent()</code> does not work properly because of <a href="https://bugs.webkit.org/show_bug.cgi?id=16735" rel="nofollow noreferrer">this webkit bug</a>  and I also found some workarounds, e.g. <a href="https://stackoverflow.com/questions/1897333/firing-a-keyboard-event-on-chrome">SO Question</a> </p>
  
  <p>However, defining properties on event object is not working because extension's content script has its own "parallel world" so properties defined in content script are not visible to web-page script.</p>
  
  <p>My only and last hope that DOM 4 Event Constructors work in Google Chrome and it would be possible to properly initialize keyboard event through constructor</p>
  
  <pre><code>var event = new KeyboardEvent("keypress", {key: 'U+0041', char: 'a', ... })
  </code></pre>
  
  <p>Unfortunately, it fails with: </p>
  
  <pre><code>TypeError: illegal constructor  
  </code></pre>
  
  <p>I was not able to find any documentation on supported event constructors in Chrome. Could anyone point me to some docs/source code?</p>
  
  <p>Any other way to simulate keyboard events in a Google Chrome extension? </p>
  
  <p>(note, TextEvent won't help because many real-world controls listen to <code>keydown</code>/<code>keyup</code> specifically) </p>