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