WebExtensions: Alternative to event.initTextEvent?

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.

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!

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