# WebExtensions: Alternative to event.initTextEvent?

**URL:** <https://discourse.mozilla.org/t/webextensions-alternative-to-event-inittextevent/5049>\
**Category:** Development\
**Created:** [November 3, 2015, 12:21am UTC](https://discourse.mozilla.org/t/webextensions-alternative-to-event-inittextevent/5049 "2015-11-03T00:21:41Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nukeador](https://sea1.discourse-cdn.com/flex001/user_avatar/discourse.mozilla.org/nukeador/32/20533_2.png) [@nukeador](https://discourse.mozilla.org/u/nukeador)\
**Post date:** [November 3, 2015, 12:21am UTC](https://discourse.mozilla.org/t/webextensions-alternative-to-event-inittextevent/5049/1 "2015-11-03T00:21:42Z")

</div>

Hello,

I’m playing with a Chrome extension to port it to Firefox but I’ve found a place where `initTextEvent` event is used to generate keypress event, but it seems [Firefox doesn’t implement it](https://developer.mozilla.org/en-US/docs/Web/API/Document/createEvent).

Code:

```
Self.fire = function(target, str) {
        // DOM 3 keyboard event doc : http://dev.w3.org/2006/webapi/DOM-Level-3-Events/html/DOM3-Events.html#events-Events-KeyboardEvent-initKeyboardEvent
        // Solution found : http://stackoverflow.com/questions/345454/how-can-i-generate-a-keypress-event-in-safari-with-javascript
        
        var eventObject = document.createEvent('TextEvent');
        eventObject.initTextEvent('textInput', true, true, null, str);
        eventObject.generatedByKeyHooker = true;
        target.dispatchEvent(eventObject);
};

```

Suggestions on alternatives working on Gecko?

Thanks!

---

<div class="post-metadata">

**Author:** ![Lithopsian](https://avatars.discourse-cdn.com/v4/letter/l/a587f6/32.png) [@Lithopsian](https://discourse.mozilla.org/u/Lithopsian)\
**Post date:** [November 3, 2015, 12:44pm UTC](https://discourse.mozilla.org/t/webextensions-alternative-to-event-inittextevent/5049/2 "2015-11-03T12:44:52Z")

</div>

You should be able to construct this with an event constructor:

> **[Creating and triggering events - Event reference | MDN](https://developer.mozilla.org/en-US/docs/Web/Events/Creating_and_triggering_events)**
>
> This article demonstrates how to create and dispatch DOM events. Such events are commonly called synthetic events, as opposed to the events fired by the browser itself.
