Uncaught InvalidStateError: Failed to execute 'dispatchEvent' on 'EventTarget': The event provided is null

Matas Vaitkevicius picture Matas Vaitkevicius · Sep 3, 2015 · Viewed 7.6k times · Source

I am getting weird behavior where Javascript event that I am trying to dispatch is not being interpreted as event while when I inspect it is is Event.

enter image description here

Then it fails with following error:

Uncaught InvalidStateError: Failed to execute 'dispatchEvent' on 'EventTarget': The event provided is null.

JSFiddle

I must be missing something obvious here.

Answer

Derek Snider picture Derek Snider · Jun 7, 2016

I just had this problem, and it was solved by cloning the event:

if (event && event.originalEvent) {
    var oe = event.originalEvent;
    this.dispatchEvent(new oe.constructor(oe.type, oe));
}