Use the `CustomEvent` constructor instead of `document.createEvent`.

According to [this page on the MDN](https://developer.mozilla.org/en-US/docs/Web/API/document.createEvent) `document.createEvent` is deprecated and [event constructors](https://developer.mozilla.org/en-US/docs/Web/API/CustomEvent) should be used instead.