(function() {
  try {
    return new KeyboardEvent(eventType, init);
  } catch (error) {
    global.window.KeyboardEvent = function(eventType, init) {
      var modKeys = [
        init.ctrlKey ? 'Control' : '',
        init.shiftKey ? 'Shift' : '',
        init.altKey ? 'Alt' : '',
        init.altGrKey ? 'AltGr' : '',
        init.metaKey ? 'Meta' : '',
      ].join(' ');
      var keyEvent = document.createEvent('KeyboardEvent');
      keyEvent.initKeyboardEvent(
        eventType,
        false,
        false,
        window,
        init.char || '',
        init.keyCode || 0,
        modKeys,
        init.repeat || false
      );
      keyEvent.key = init.key;

      return keyEvent;
    }
  }
})();

@@ -13,77 +13,128 @@
 %7B%0A  
-try %7B%0A    return new KeyboardEvent(eventType, init);%0A  %7D catch (error
+// critically in Phantom JS it is an object so can't be used as a constructor.%0A  if (typeof KeyboardEvent !== 'function'
 ) %7B%0A

Check for type then fill.