Closed danieltroger closed 2 years ago
Nevermind, it's a bug in the testcafe code
It's actually this in the original code:
function waitForFileDownload() {
return delay$2(FILE_DOWNLOAD_CHECK_DELAY)
.then(function () { return transport.queuedAsyncServiceMsg({ cmd: MESSAGE.waitForFileDownload }); })
// eslint-disable-next-line consistent-return
.then(function (fileDownloadingHandled) {
// NOTE: we use a flag to confirm file download because if unload
// is raised the browser can respond with an empty string
if (!fileDownloadingHandled)
return Promise$2(function () { });
});
}
Which is missing the new
Uglify version (
uglifyjs -V
)JavaScript input
Input code
```typescript window['%hammerhead%'].utils.removeInjectedScript(); // NOTE: We should have the capability to initialize scripts with different contexts. // This is required for iframes without the src attribute because Hammerhead does not // inject scripts into such iframes. So, we wrap all scripts in initialization functions. (function () { function initTestCafeCore(window, isIFrameWithoutSrc) { var document = window.document; (function (hammerhead, Promise$5) { var hammerhead__default = 'default' in hammerhead ? hammerhead['default'] : hammerhead; Promise$5 = Promise$5 && Object.prototype.hasOwnProperty.call(Promise$5, 'default') ? Promise$5['default'] : Promise$5; // @ts-ignore var emptyAdapter = {}; function initializeAdapter(initializer) { // eslint-disable-next-line no-restricted-globals var keys = Object.keys(initializer); for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) { var key = keys_1[_i]; // @ts-ignore emptyAdapter[key] = initializer[key]; } } // @ts-ignore var adapter = {}; function initializeAdapter$1(initializer) { if (initializer.nativeMethods.objectAssign) { initializer.nativeMethods.objectAssign(adapter, initializer); return; } var keys = initializer.nativeMethods.objectKeys(initializer); for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) { var key = keys_1[_i]; // @ts-ignore adapter[key] = initializer[key]; } } var EventEmitter = /** @class */ (function () { function EventEmitter() { this._eventsListeners = {}; } EventEmitter.prototype.on = function (evt, listener) { if (!this._eventsListeners[evt]) this._eventsListeners[evt] = []; this._eventsListeners[evt].push(listener); }; EventEmitter.prototype.once = function (evt, listener) { var _this = this; this.on(evt, function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } _this.off(evt, listener); return listener.apply(void 0, args); }); }; EventEmitter.prototype.off = function (evt, listener) { var listeners = this._eventsListeners[evt]; if (listeners) this._eventsListeners[evt] = adapter.nativeMethods.arrayFilter.call(listeners, function (item) { return item !== listener; }); }; EventEmitter.prototype.offAll = function (evt) { if (evt) this._eventsListeners[evt] = []; else this._eventsListeners = {}; }; EventEmitter.prototype.emit = function (evt) { var args = []; for (var _i = 1; _i < arguments.length; _i++) { args[_i - 1] = arguments[_i]; } var listeners = this._eventsListeners[evt]; if (!listeners) return; for (var i = 0; i < listeners.length; i++) { try { listeners[i].apply(this, args); } catch (e) { // Hack for IE: after document.write calling IFrameSandbox event handlers // rises 'Can't execute code from a freed script' exception because document has been // recreated if (e.message && e.message.indexOf('freed script') > -1) this.off(evt, listeners[i]); else throw e; } } }; return EventEmitter; }()); var EventEmitter$1 = EventEmitter; function inherit(Child, Parent) { var Func = function () { }; Func.prototype = Parent.prototype; hammerhead__default.utils.extend(Child.prototype, new Func()); Child.prototype.constructor = Child; Child.base = Parent.prototype; } var serviceUtils = /*#__PURE__*/Object.freeze({ __proto__: null, EventEmitter: EventEmitter$1, inherit: inherit }); /*! ***************************************************************************** Copyright (c) Microsoft Corporation. Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ***************************************************************************** */ /* global Reflect, Promise */ var extendStatics = function(d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; return extendStatics(d, b); }; function __extends(d, b) { extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); } function __rest(s, e) { var t = {}; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p]; if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]]; } return t; } function __awaiter(thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise$5))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); } function __generator(thisArg, body) { var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; function verb(n) { return function (v) { return step([n, v]); }; } function step(op) { if (f) throw new TypeError("Generator is already executing."); while (_) try { if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; if (y = 0, t) op = [op[0] & 2, t.value]; switch (op[0]) { case 0: case 1: t = op; break; case 4: _.label++; return { value: op[1], done: false }; case 5: _.label++; y = op[1]; op = [0]; continue; case 7: op = _.ops.pop(); _.trys.pop(); continue; default: if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } if (t[2]) _.ops.pop(); _.trys.pop(); continue; } op = body.call(thisArg, _); } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; } } function __spreadArrays() { for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length; for (var r = Array(s), k = 0, i = 0; i < il; i++) for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++) r[k] = a[j]; return r; } var ARRAY_METHODS_PREFIX = 'array'; function createNativeMethodWrapper(methodName) { var nativeMethodName = ARRAY_METHODS_PREFIX + methodName.charAt(0).toUpperCase() + methodName.slice(1); var nativeMethod = hammerhead.nativeMethods[nativeMethodName]; return function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } return nativeMethod.call.apply(nativeMethod, args); }; } var filter = createNativeMethodWrapper('filter'); var map = createNativeMethodWrapper('map'); var slice = createNativeMethodWrapper('slice'); var splice = createNativeMethodWrapper('splice'); var unshift = createNativeMethodWrapper('unshift'); var forEach = createNativeMethodWrapper('forEach'); var indexOf = createNativeMethodWrapper('indexOf'); var some = createNativeMethodWrapper('some'); var reverse = createNativeMethodWrapper('reverse'); var reduce = createNativeMethodWrapper('reduce'); var concat = createNativeMethodWrapper('concat'); var join = createNativeMethodWrapper('join'); function isArray(arg) { return hammerhead.nativeMethods.objectToString.call(arg) === '[object Array]'; } function from(arg) { var args = []; for (var _i = 1; _i < arguments.length; _i++) { args[_i - 1] = arguments[_i]; } if (hammerhead.nativeMethods.arrayFrom) return hammerhead.nativeMethods.arrayFrom.apply(hammerhead.nativeMethods, __spreadArrays([arg], args)); // NOTE: this logic is for IE var arr = []; var length = arg.length; for (var i = 0; i < length; i++) arr.push(arg[i]); return arr; } function find(arr, callback) { if (hammerhead.nativeMethods.arrayFind) return hammerhead.nativeMethods.arrayFind.call(arr, callback); // NOTE: this logic is for IE var length = arr.length; for (var i = 0; i < length; i++) { if (callback(arr[i], i, arr)) return arr[i]; } return null; } function remove(arr, item) { var index = hammerhead.nativeMethods.arrayIndexOf.call(arr, item); if (index > -1) hammerhead.nativeMethods.arraySplice.call(arr, index, 1); } function equals(arr1, arr2) { if (arr1.length !== arr2.length) return false; for (var i = 0, l = arr1.length; i < l; i++) { if (arr1[i] !== arr2[i]) return false; } return true; } function getCommonElement(arr1, arr2) { for (var i = 0; i < arr1.length; i++) { for (var t = 0; t < arr2.length; t++) { if (arr1[i] === arr2[t]) return arr1[i]; } } return null; } var arrayUtils = /*#__PURE__*/Object.freeze({ __proto__: null, filter: filter, map: map, slice: slice, splice: splice, unshift: unshift, forEach: forEach, indexOf: indexOf, some: some, reverse: reverse, reduce: reduce, concat: concat, join: join, isArray: isArray, from: from, find: find, remove: remove, equals: equals, getCommonElement: getCommonElement }); var browserUtils = hammerhead__default.utils.browser; var nativeMethods = hammerhead__default.nativeMethods; // NOTE: We have to retrieve styleUtils.get from hammerhead // to avoid circular dependencies between domUtils and styleUtils var getElementStyleProperty = hammerhead__default.utils.style.get; var getActiveElement = hammerhead__default.utils.dom.getActiveElement; var findDocument = hammerhead__default.utils.dom.findDocument; var isElementInDocument = hammerhead__default.utils.dom.isElementInDocument; var isElementInIframe = hammerhead__default.utils.dom.isElementInIframe; var getIframeByElement = hammerhead__default.utils.dom.getIframeByElement; var isCrossDomainWindows = hammerhead__default.utils.dom.isCrossDomainWindows; var getSelectParent = hammerhead__default.utils.dom.getSelectParent; var getChildVisibleIndex = hammerhead__default.utils.dom.getChildVisibleIndex; var getSelectVisibleChildren = hammerhead__default.utils.dom.getSelectVisibleChildren; var isElementNode = hammerhead__default.utils.dom.isElementNode; var isTextNode = hammerhead__default.utils.dom.isTextNode; var isRenderedNode = hammerhead__default.utils.dom.isRenderedNode; var isIframeElement = hammerhead__default.utils.dom.isIframeElement; var isInputElement = hammerhead__default.utils.dom.isInputElement; var isButtonElement = hammerhead__default.utils.dom.isButtonElement; var isFileInput = hammerhead__default.utils.dom.isFileInput; var isTextAreaElement = hammerhead__default.utils.dom.isTextAreaElement; var isAnchorElement = hammerhead__default.utils.dom.isAnchorElement; var isImgElement = hammerhead__default.utils.dom.isImgElement; var isFormElement = hammerhead__default.utils.dom.isFormElement; var isLabelElement = hammerhead__default.utils.dom.isLabelElement; var isSelectElement = hammerhead__default.utils.dom.isSelectElement; var isRadioButtonElement = hammerhead__default.utils.dom.isRadioButtonElement; var isColorInputElement = hammerhead__default.utils.dom.isColorInputElement; var isCheckboxElement = hammerhead__default.utils.dom.isCheckboxElement; var isOptionElement = hammerhead__default.utils.dom.isOptionElement; var isSVGElement = hammerhead__default.utils.dom.isSVGElement; var isMapElement = hammerhead__default.utils.dom.isMapElement; var isBodyElement = hammerhead__default.utils.dom.isBodyElement; var isHtmlElement = hammerhead__default.utils.dom.isHtmlElement; var isDocument = hammerhead__default.utils.dom.isDocument; var isWindow = hammerhead__default.utils.dom.isWindow; var isTextEditableInput = hammerhead__default.utils.dom.isTextEditableInput; var isTextEditableElement = hammerhead__default.utils.dom.isTextEditableElement; var isTextEditableElementAndEditingAllowed = hammerhead__default.utils.dom.isTextEditableElementAndEditingAllowed; var isContentEditableElement = hammerhead__default.utils.dom.isContentEditableElement; var isDomElement = hammerhead__default.utils.dom.isDomElement; var isShadowUIElement = hammerhead__default.utils.dom.isShadowUIElement; var isShadowRoot = hammerhead__default.utils.dom.isShadowRoot; var isElementFocusable = hammerhead__default.utils.dom.isElementFocusable; var isHammerheadAttr = hammerhead__default.utils.dom.isHammerheadAttr; var isElementReadOnly = hammerhead__default.utils.dom.isElementReadOnly; var getScrollbarSize = hammerhead__default.utils.dom.getScrollbarSize; var getMapContainer = hammerhead__default.utils.dom.getMapContainer; var getTagName = hammerhead__default.utils.dom.getTagName; var closest = hammerhead__default.utils.dom.closest; var getParents = hammerhead__default.utils.dom.getParents; var findParent = hammerhead__default.utils.dom.findParent; var getTopSameDomainWindow = hammerhead__default.utils.dom.getTopSameDomainWindow; var getParentExceptShadowRoot = hammerhead__default.utils.dom.getParentExceptShadowRoot; function canFocus(element, parent, tabIndex) { var activeElement = null; if (parent.nodeType === Node.DOCUMENT_NODE) activeElement = nativeMethods.documentActiveElementGetter.call(parent); if (element === activeElement) return true; if (element.disabled) return false; if (getElementStyleProperty(element, 'display') === 'none' || getElementStyleProperty(element, 'visibility') === 'hidden') return false; if ((browserUtils.isIE || browserUtils.isAndroid) && isOptionElement(element)) return false; if (tabIndex !== null && tabIndex < 0) return false; return true; } function wrapElement(el) { return { el: el, skip: el.shadowRoot && el.tabIndex < 0, children: {}, }; } function buildFocusableTree(parent, sort) { var node = wrapElement(parent); parent = parent.shadowRoot || parent; if (isIframeElement(parent)) parent = nativeMethods.contentDocumentGetter.call(parent); if (parent && (parent.nodeType === Node.DOCUMENT_FRAGMENT_NODE || parent.nodeType === Node.DOCUMENT_NODE)) { var elements = filterFocusableElements(parent); for (var _i = 0, elements_1 = elements; _i < elements_1.length; _i++) { var el = elements_1[_i]; var key = !sort || el.tabIndex <= 0 ? -1 : el.tabIndex; node.children[key] = node.children[key] || []; node.children[key].push(buildFocusableTree(el, sort)); } } return node; } function filterFocusableElements(parent) { // NOTE: We don't take into account the case of embedded contentEditable // elements and specify the contentEditable attribute for focusable elements var allElements = parent.querySelectorAll('*'); var invisibleElements = getInvisibleElements(allElements); var inputElementsRegExp = /^(input|button|select|textarea)$/; var focusableElements = []; var element = null; var tagName = null; var tabIndex = null; var needPush = false; for (var i = 0; i < allElements.length; i++) { element = allElements[i]; tagName = getTagName(element); tabIndex = getTabIndexAttributeIntValue(element); needPush = false; if (!canFocus(element, parent, tabIndex)) continue; if (inputElementsRegExp.test(tagName)) needPush = true; else if (element.shadowRoot) needPush = true; else if (isIframeElement(element)) needPush = true; else if (isAnchorElement(element) && element.hasAttribute('href')) needPush = element.getAttribute('href') !== '' || !browserUtils.isIE || tabIndex !== null; var contentEditableAttr = element.getAttribute('contenteditable'); if (contentEditableAttr === '' || contentEditableAttr === 'true') needPush = true; if (tabIndex !== null) needPush = true; if (needPush) focusableElements.push(element); } //NOTE: remove children of invisible elements return filter(focusableElements, function (el) { return !containsElement(invisibleElements, el); }); } function flattenFocusableTree(node) { var result = []; if (!node.skip && node.el.nodeType !== Node.DOCUMENT_NODE && !isIframeElement(node.el)) result.push(node.el); for (var prop in node.children) { for (var _i = 0, _a = node.children[prop]; _i < _a.length; _i++) { var childNode = _a[_i]; result.push.apply(result, flattenFocusableTree(childNode)); } } return result; } function getFocusableElements(doc, sort) { if (sort === void 0) { sort = false; } var root = buildFocusableTree(doc, sort); return flattenFocusableTree(root); } function getInvisibleElements(elements) { var invisibleElements = []; for (var i = 0; i < elements.length; i++) { if (getElementStyleProperty(elements[i], 'display') === 'none') invisibleElements.push(elements[i]); } return invisibleElements; } function getTabIndexAttributeIntValue(el) { var tabIndex = nativeMethods.getAttribute.call(el, 'tabindex'); if (tabIndex !== null) { tabIndex = parseInt(tabIndex, 10); tabIndex = isNaN(tabIndex) ? null : tabIndex; } return tabIndex; } function containsElement(elements, element) { if (elements.contains) return elements.contains(element); return some(elements, function (parent) { return parent.contains(element); }); } function getTextareaIndentInLine(textarea, position) { var textareaValue = getTextAreaValue(textarea); if (!textareaValue) return 0; var topPart = textareaValue.substring(0, position); var linePosition = topPart.lastIndexOf('\n') === -1 ? 0 : topPart.lastIndexOf('\n') + 1; return position - linePosition; } function getTextareaLineNumberByPosition(textarea, position) { var textareaValue = getTextAreaValue(textarea); var lines = textareaValue.split('\n'); var topPartLength = 0; var line = 0; for (var i = 0; topPartLength <= position; i++) { if (position <= topPartLength + lines[i].length) { line = i; break; } topPartLength += lines[i].length + 1; } return line; } function getTextareaPositionByLineAndOffset(textarea, line, offset) { var textareaValue = getTextAreaValue(textarea); var lines = textareaValue.split('\n'); var lineIndex = 0; for (var i = 0; i < line; i++) lineIndex += lines[i].length + 1; return lineIndex + offset; } // NOTE: the form is also submitted on enter key press if there is only one input of certain // types (referred to as types that block implicit submission in the HTML5 standard) on the // form and this input is focused (http://www.w3.org/TR/html5/forms.html#implicit-submission) function blocksImplicitSubmission(el) { var inputTypeRegExp = null; if (browserUtils.isSafari) inputTypeRegExp = /^(text|password|color|date|time|datetime|datetime-local|email|month|number|search|tel|url|week|image)$/i; else if (browserUtils.isFirefox) inputTypeRegExp = /^(text|password|date|time|datetime|datetime-local|email|month|number|search|tel|url|week|image)$/i; else if (browserUtils.isIE) inputTypeRegExp = /^(text|password|color|date|time|datetime|datetime-local|email|file|month|number|search|tel|url|week|image)$/i; else inputTypeRegExp = /^(text|password|datetime|email|number|search|tel|url|image)$/i; return inputTypeRegExp.test(el.type); } function isEditableElement(el, checkEditingAllowed) { return checkEditingAllowed ? isTextEditableElementAndEditingAllowed(el) || isContentEditableElement(el) : isTextEditableElement(el) || isContentEditableElement(el); } function isElementContainsNode(parentElement, childNode) { if (isTheSameNode(childNode, parentElement)) return true; var childNodes = nativeMethods.nodeChildNodesGetter.call(parentElement); var length = getChildNodesLength(childNodes); for (var i = 0; i < length; i++) { var el = childNodes[i]; if (!isShadowUIElement(el) && isElementContainsNode(el, childNode)) return true; } return false; } function isOptionGroupElement(element) { return hammerhead__default.utils.dom.instanceToString(element) === '[object HTMLOptGroupElement]'; } function getElementIndexInParent(parent, child) { var children = parent.querySelectorAll(getTagName(child)); return indexOf(children, child); } function isTheSameNode(node1, node2) { //NOTE: Mozilla has not isSameNode method if (node1 && node2 && node1.isSameNode) return node1.isSameNode(node2); return node1 === node2; } function getElementDescription(el) { var attributes = { id: 'id', name: 'name', 'class': 'className', }; var res = []; res.push('<'); res.push(getTagName(el)); for (var attr in attributes) { if (attributes.hasOwnProperty(attr)) { var val = el[attributes[attr]]; if (val) res.push(' ' + attr + '="' + val + '"'); } } res.push('>'); return res.join(''); } function getFocusableParent(el) { var parents = getParents(el); for (var i = 0; i < parents.length; i++) { if (isElementFocusable(parents[i])) return parents[i]; } return null; } function remove$1(el) { if (el && el.parentElement) el.parentElement.removeChild(el); } function isIFrameWindowInDOM(win) { //NOTE: In MS Edge, if an iframe is removed from DOM, the browser throws an exception when accessing window.top //and window.frameElement. Fortunately, setTimeout is set to undefined in this case. if (!win.setTimeout) return false; var frameElement = null; try { //NOTE: This may raise a cross-domain policy error in some browsers. frameElement = win.frameElement; } catch (e) { return !!win.top; } // NOTE: in Firefox and WebKit, frameElement is null for cross-domain iframes even if they are in the DOM. // But these browsers don't execute scripts in removed iframes, so we suppose that the iframe is in the DOM. if ((browserUtils.isFirefox || browserUtils.isWebKit) && win.top !== win && !frameElement) return true; return !!(frameElement && nativeMethods.contentDocumentGetter.call(frameElement)); } function isTopWindow(win) { try { //NOTE: MS Edge throws an exception when trying to access window.top from an iframe removed from DOM return win.top === win; } catch (e) { return false; } } function findIframeByWindow(iframeWindow, iframeDestinationWindow) { var iframes = (iframeDestinationWindow || window).document.getElementsByTagName('iframe'); for (var i = 0; i < iframes.length; i++) { if (nativeMethods.contentWindowGetter.call(iframes[i]) === iframeWindow) return iframes[i]; } return null; } function isEditableFormElement(element) { return isTextEditableElement(element) || isSelectElement(element); } function getCommonAncestor(element1, element2) { if (isTheSameNode(element1, element2)) return element1; var el1Parents = [element1].concat(getParents(element1)); var commonAncestor = element2; while (commonAncestor) { if (indexOf(el1Parents, commonAncestor) > -1) return commonAncestor; commonAncestor = nativeMethods.nodeParentNodeGetter.call(commonAncestor); } return commonAncestor; } function getChildrenLength(children) { return nativeMethods.htmlCollectionLengthGetter.call(children); } function getChildNodesLength(childNodes) { return nativeMethods.nodeListLengthGetter.call(childNodes); } function getInputValue(input) { return nativeMethods.inputValueGetter.call(input); } function getTextAreaValue(textArea) { return nativeMethods.textAreaValueGetter.call(textArea); } function setInputValue(input, value) { return nativeMethods.inputValueSetter.call(input, value); } function setTextAreaValue(textArea, value) { return nativeMethods.textAreaValueSetter.call(textArea, value); } function getElementValue(element) { if (isInputElement(element)) return getInputValue(element); else if (isTextAreaElement(element)) return getTextAreaValue(element); /*eslint-disable no-restricted-properties*/ return element.value; /*eslint-enable no-restricted-properties*/ } function setElementValue(element, value) { if (isInputElement(element)) return setInputValue(element, value); else if (isTextAreaElement(element)) return setTextAreaValue(element, value); /*eslint-disable no-restricted-properties*/ element.value = value; /*eslint-enable no-restricted-properties*/ return value; } function isShadowElement(element) { return element && element.getRootNode && findDocument(element) !== element.getRootNode(); } function contains(element, target) { if (!element || !target) return false; if (element.contains) return element.contains(target); return !!findParent(target, true, function (node) { return node === element; }); } var domUtils = /*#__PURE__*/Object.freeze({ __proto__: null, getActiveElement: getActiveElement, findDocument: findDocument, isElementInDocument: isElementInDocument, isElementInIframe: isElementInIframe, getIframeByElement: getIframeByElement, isCrossDomainWindows: isCrossDomainWindows, getSelectParent: getSelectParent, getChildVisibleIndex: getChildVisibleIndex, getSelectVisibleChildren: getSelectVisibleChildren, isElementNode: isElementNode, isTextNode: isTextNode, isRenderedNode: isRenderedNode, isIframeElement: isIframeElement, isInputElement: isInputElement, isButtonElement: isButtonElement, isFileInput: isFileInput, isTextAreaElement: isTextAreaElement, isAnchorElement: isAnchorElement, isImgElement: isImgElement, isFormElement: isFormElement, isLabelElement: isLabelElement, isSelectElement: isSelectElement, isRadioButtonElement: isRadioButtonElement, isColorInputElement: isColorInputElement, isCheckboxElement: isCheckboxElement, isOptionElement: isOptionElement, isSVGElement: isSVGElement, isMapElement: isMapElement, isBodyElement: isBodyElement, isHtmlElement: isHtmlElement, isDocument: isDocument, isWindow: isWindow, isTextEditableInput: isTextEditableInput, isTextEditableElement: isTextEditableElement, isTextEditableElementAndEditingAllowed: isTextEditableElementAndEditingAllowed, isContentEditableElement: isContentEditableElement, isDomElement: isDomElement, isShadowUIElement: isShadowUIElement, isShadowRoot: isShadowRoot, isElementFocusable: isElementFocusable, isHammerheadAttr: isHammerheadAttr, isElementReadOnly: isElementReadOnly, getScrollbarSize: getScrollbarSize, getMapContainer: getMapContainer, getTagName: getTagName, closest: closest, getParents: getParents, findParent: findParent, getTopSameDomainWindow: getTopSameDomainWindow, getParentExceptShadowRoot: getParentExceptShadowRoot, getFocusableElements: getFocusableElements, getTabIndexAttributeIntValue: getTabIndexAttributeIntValue, containsElement: containsElement, getTextareaIndentInLine: getTextareaIndentInLine, getTextareaLineNumberByPosition: getTextareaLineNumberByPosition, getTextareaPositionByLineAndOffset: getTextareaPositionByLineAndOffset, blocksImplicitSubmission: blocksImplicitSubmission, isEditableElement: isEditableElement, isElementContainsNode: isElementContainsNode, isOptionGroupElement: isOptionGroupElement, getElementIndexInParent: getElementIndexInParent, isTheSameNode: isTheSameNode, getElementDescription: getElementDescription, getFocusableParent: getFocusableParent, remove: remove$1, isIFrameWindowInDOM: isIFrameWindowInDOM, isTopWindow: isTopWindow, findIframeByWindow: findIframeByWindow, isEditableFormElement: isEditableFormElement, getCommonAncestor: getCommonAncestor, getChildrenLength: getChildrenLength, getChildNodesLength: getChildNodesLength, getInputValue: getInputValue, getTextAreaValue: getTextAreaValue, setInputValue: setInputValue, setTextAreaValue: setTextAreaValue, getElementValue: getElementValue, setElementValue: setElementValue, isShadowElement: isShadowElement, contains: contains }); var listeners = hammerhead.eventSandbox.listeners; var ScrollController = /** @class */ (function () { function ScrollController() { this.initialized = false; this.stopPropagationFlag = false; this.events = new EventEmitter$1(); } ScrollController.prototype._internalListener = function (event, dispatched, preventEvent, cancelHandlers, stopPropagation) { this.events.emit('scroll', event); if (this.stopPropagationFlag) { cancelHandlers(); stopPropagation(); } }; ScrollController.prototype.init = function () { var _this = this; if (this.initialized) return; this.initialized = true; listeners.initElementListening(window, ['scroll']); listeners.addFirstInternalEventBeforeListener(window, ['scroll'], function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } return _this._internalListener.apply(_this, args); }); }; ScrollController.prototype.waitForScroll = function (scrollElement) { var _this = this; var promiseResolver = null; var promise = new hammerhead.Promise(function (resolve) { promiseResolver = resolve; }); promise.cancel = function () { return _this.events.off('scroll', promiseResolver); }; if (this.initialized) this.handleScrollEvents(scrollElement, promiseResolver); else promiseResolver(); return promise; }; ScrollController.prototype.handleScrollEvents = function (el, handler) { var _this = this; this.events.once('scroll', handler); if (isShadowElement(el)) { listeners.initElementListening(el, ['scroll']); listeners.addFirstInternalEventBeforeListener(el, ['scroll'], function () { var args = []; for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } _this._internalListener.apply(_this, args); listeners.cancelElementListening(el); }); } }; ScrollController.prototype.stopPropagation = function () { this.stopPropagationFlag = true; }; ScrollController.prototype.enablePropagation = function () { this.stopPropagationFlag = false; }; return ScrollController; }()); var scrollController = new ScrollController(); // @ts-ignore initializeAdapter({ PromiseCtor: hammerhead.Promise, controller: scrollController, }); var browserUtils$1 = hammerhead__default.utils.browser; var MODIFIERS = { alt: 18, ctrl: 17, meta: 91, shift: 16, }; var SHIFT_MAP = { '~': '`', '!': '1', '@': '2', '#': '3', '$': '4', '%': '5', '^': '6', '&': '7', '*': '8', '(': '9', ')': '0', '_': '-', '+': '=', '{': '[', '}': ']', ':': ';', '"': '\'', '|': '\\', '<': ',', '>': '.', '?': '/', '±': '§', }; var SPECIAL_KEYS = { backspace: 8, capslock: 20, delete: 46, down: 40, end: 35, enter: 13, esc: 27, home: 36, ins: 45, left: 37, pagedown: 34, pageup: 33, right: 39, space: 32, tab: 9, up: 38, }; var KEY_PROPERTY = { left: browserUtils$1.isIE ? 'Left' : 'ArrowLeft', down: browserUtils$1.isIE ? 'Down' : 'ArrowDown', right: browserUtils$1.isIE ? 'Right' : 'ArrowRight', up: browserUtils$1.isIE ? 'Up' : 'ArrowUp', backspace: 'Backspace', capslock: 'CapsLock', delete: 'Delete', end: 'End', enter: 'Enter', esc: 'Escape', home: 'Home', ins: 'Insert', pagedown: 'PageDown', pageup: 'PageUp', space: browserUtils$1.isIE ? 'Spacebar' : ' ', tab: 'Tab', alt: 'Alt', ctrl: 'Control', meta: 'Meta', shift: 'Shift', }; function reverseMap(map) { var reversed = {}; for (var key in map) { if (map.hasOwnProperty(key)) reversed[map[key]] = key; } return reversed; } var KEY_MAPS = { modifiers: MODIFIERS, shiftMap: SHIFT_MAP, specialKeys: SPECIAL_KEYS, keyProperty: KEY_PROPERTY, modifiersMap: { option: 'alt', }, symbolCharCodeToKeyCode: { 96: 192, 91: 219, 93: 221, 92: 220, 59: 186, 39: 222, 44: 188, 45: browserUtils$1.isFirefox ? 173 : 189, 46: 190, 47: 191, }, symbolKeysCharCodes: { 109: 45, 173: 45, 186: 59, 187: 61, 188: 44, 189: 45, 190: 46, 191: 47, 192: 96, 219: 91, 220: 92, 221: 93, 222: 39, 110: 46, 96: 48, 97: 49, 98: 50, 99: 51, 100: 52, 101: 53, 102: 54, 103: 55, 104: 56, 105: 57, 107: 43, 106: 42, 111: 47, }, reversedModifiers: reverseMap(MODIFIERS), reversedShiftMap: reverseMap(SHIFT_MAP), reversedSpecialKeys: reverseMap(SPECIAL_KEYS), reversedKeyProperty: reverseMap(KEY_PROPERTY), }; function delay(ms) { return new Promise$5(function (resolve) { return setTimeout(resolve, ms); }); } var REQUESTS_COLLECTION_DELAY_DEFAULT = 50; var RequestBarrier = /** @class */ (function () { function RequestBarrier(emitter, delays) { if (delays === void 0) { delays = {}; } var _a, _b, _c; this._delays = { requestsCollection: (_a = delays.requestsCollection) !== null && _a !== void 0 ? _a : REQUESTS_COLLECTION_DELAY_DEFAULT, additionalRequestsCollection: (_b = delays.additionalRequestsCollection) !== null && _b !== void 0 ? _b : REQUESTS_COLLECTION_DELAY_DEFAULT, pageInitialRequestsCollection: (_c = delays.pageInitialRequestsCollection) !== null && _c !== void 0 ? _c : REQUESTS_COLLECTION_DELAY_DEFAULT, }; this._emitter = emitter; this._waitResolve = null; this._watchdog = null; this._requests = new Set(); this._collectingReqs = true; this._startListening(); } RequestBarrier.prototype._startListening = function () { var _this = this; this._emitter.onRequestSend(function (req) { return _this._onRequestSend(req); }); this._emitter.onRequestCompleted(function (req) { return _this._onRequestCompleted(req); }); this._emitter.onRequestError(function (req) { return _this._onRequestError(req); }); }; RequestBarrier.prototype._offListening = function () { this._emitter.offAll(); }; RequestBarrier.prototype._onRequestSend = function (req) { if (this._collectingReqs) this._requests.add(req); }; RequestBarrier.prototype._onRequestCompleted = function (req) { var _this = this; // NOTE: let the last real XHR handler finish its job and try to obtain // any additional requests if they were initiated by this handler delay(this._delays.additionalRequestsCollection) .then(function () { return _this._onRequestFinished(req); }); }; RequestBarrier.prototype._onRequestFinished = function (req) { if (!this._requests.has(req)) return; this._requests.delete(req); if (!this._collectingReqs && !this._requests.size && this._watchdog) this._finishWaiting(); }; RequestBarrier.prototype._onRequestError = function (req) { this._onRequestFinished(req); }; RequestBarrier.prototype._finishWaiting = function () { if (this._watchdog) { var clearTimeout_1 = adapter.nativeMethods.clearTimeout; clearTimeout_1(this._watchdog); this._watchdog = null; } this._requests.clear(); this._offListening(); this._waitResolve(); // eslint-disable-line @typescript-eslint/no-non-null-assertion }; RequestBarrier.prototype.wait = function (isPageLoad) { var _this = this; return delay(isPageLoad ? this._delays.pageInitialRequestsCollection : this._delays.requestsCollection) .then(function () { return new adapter.PromiseCtor(function (resolve) { _this._collectingReqs = false; _this._waitResolve = resolve; if (!_this._requests.size) { _this._finishWaiting(); return; } var setTimeout = adapter.nativeMethods.setTimeout; _this._watchdog = setTimeout(function () { return _this._finishWaiting(); }, RequestBarrier.TIMEOUT); }); }); }; RequestBarrier.TIMEOUT = 3000; return RequestBarrier; }()); var REQUEST_SEND_EVENT = 'request-send'; var REQUEST_COMPLETED_EVENT = 'request-completed'; var REQUEST_ERROR_EVENT = 'request-error'; var HammerheadClientRequestEmitter = /** @class */ (function (_super) { __extends(HammerheadClientRequestEmitter, _super); function HammerheadClientRequestEmitter() { var _this = _super.call(this) || this; _this._hammerheadListenersInfo = []; _this._addHammerheadListener(hammerhead__default.EVENTS.beforeXhrSend, function (_a) { var xhr = _a.xhr; return _this.emit(REQUEST_SEND_EVENT, xhr); }); _this._addHammerheadListener(hammerhead__default.EVENTS.xhrCompleted, function (_a) { var xhr = _a.xhr; return _this.emit(REQUEST_COMPLETED_EVENT, xhr); }); _this._addHammerheadListener(hammerhead__default.EVENTS.xhrError, function (_a) { var xhr = _a.xhr; return _this.emit(REQUEST_ERROR_EVENT, xhr); }); _this._addHammerheadListener(hammerhead__default.EVENTS.fetchSent, function (fetch) { _this.emit(REQUEST_SEND_EVENT, fetch); fetch.then(function () { return _this.emit(REQUEST_COMPLETED_EVENT, fetch); }, function () { return _this.emit(REQUEST_ERROR_EVENT, fetch); }); }); return _this; } HammerheadClientRequestEmitter.prototype._addHammerheadListener = function (evt, listener) { hammerhead__default.on(evt, listener); this._hammerheadListenersInfo.push({ evt: evt, listener: listener }); }; HammerheadClientRequestEmitter.prototype.onRequestSend = function (listener) { this.on(REQUEST_SEND_EVENT, listener); }; HammerheadClientRequestEmitter.prototype.onRequestCompleted = function (listener) { this.on(REQUEST_COMPLETED_EVENT, listener); }; HammerheadClientRequestEmitter.prototype.onRequestError = function (listener) { this.on(REQUEST_ERROR_EVENT, listener); }; HammerheadClientRequestEmitter.prototype.offAll = function () { _super.prototype.offAll.call(this); for (var _i = 0, _a = this._hammerheadListenersInfo; _i < _a.length; _i++) { var info = _a[_i]; hammerhead__default.off.call(hammerhead__default, info.evt, info.listener); } }; return HammerheadClientRequestEmitter; }(EventEmitter)); function delay$1(ms) { var setTimeout = adapter.nativeMethods.setTimeout; return new adapter.PromiseCtor(function (resolve) { return setTimeout(resolve, ms); }); } var WAIT_FOR_NEW_SCRIPTS_DELAY = 25; var ScriptExecutionBarrier = /** @class */ (function () { function ScriptExecutionBarrier(emitter) { this._emitter = emitter; this._watchdog = null; this._waitResolve = null; this._scripts = new Map(); this._startListening(); } ScriptExecutionBarrier.prototype._startListening = function () { var _this = this; this._emitter.onScriptAdded(function (script) { return _this._onScriptElementAdded(script); }); this._emitter.onScriptLoadedOrFailed(function (script) { return _this._onScriptLoadedOrFailed(script); }); }; ScriptExecutionBarrier.prototype._offListening = function () { this._emitter.offAll(); }; ScriptExecutionBarrier.prototype._onScriptElementAdded = function (script) { var _this = this; var setTimeout = adapter.nativeMethods.setTimeout; var timeoutFn = function () { return _this._onScriptLoadedOrFailed(script, true); }; var loadingTimeout = setTimeout(timeoutFn, ScriptExecutionBarrier.LOADING_TIMEOUT); this._scripts.set(script, loadingTimeout); }; ScriptExecutionBarrier.prototype._onScriptLoadedOrFailed = function (script, isTimeout) { var _this = this; if (isTimeout === void 0) { isTimeout = false; } if (!this._scripts.has(script)) return; if (!isTimeout) { var clearTimeout_1 = adapter.nativeMethods.clearTimeout; clearTimeout_1(this._scripts.get(script)); } this._scripts.delete(script); if (this._scripts.size) return; delay$1(WAIT_FOR_NEW_SCRIPTS_DELAY) .then(function () { if (_this._waitResolve && !_this._scripts.size) _this._finishWaiting(); }); }; ScriptExecutionBarrier.prototype._finishWaiting = function () { if (this._watchdog) { var clearTimeout_2 = adapter.nativeMethods.clearTimeout; clearTimeout_2(this._watchdog); this._watchdog = null; } this._scripts.clear(); this._offListening(); this._waitResolve(); // eslint-disable-line @typescript-eslint/no-non-null-assertion this._waitResolve = null; }; ScriptExecutionBarrier.prototype.wait = function () { var _this = this; return new adapter.PromiseCtor(function (resolve) { _this._waitResolve = resolve; if (!_this._scripts.size) { _this._finishWaiting(); return; } var setTimeout = adapter.nativeMethods.setTimeout; _this._watchdog = setTimeout(function () { return _this._finishWaiting(); }, ScriptExecutionBarrier.TIMEOUT); }); }; ScriptExecutionBarrier.TIMEOUT = 3000; ScriptExecutionBarrier.LOADING_TIMEOUT = 2000; return ScriptExecutionBarrier; }()); var nativeMethods$1 = hammerhead__default.nativeMethods; var SCRIPT_ADDED = 'script-added'; var SCRIPT_LOADED_OR_FAILED = 'script-loaded-or-failed'; var HammerheadScriptExecutionEmitter = /** @class */ (function (_super) { __extends(HammerheadScriptExecutionEmitter, _super); function HammerheadScriptExecutionEmitter() { var _this = _super.call(this) || this; _this._scriptElementAddedListener = function (_a) { var el = _a.el; return _this._onScriptElementAdded(el); }; hammerhead__default.on(hammerhead__default.EVENTS.scriptElementAdded, _this._scriptElementAddedListener); return _this; } HammerheadScriptExecutionEmitter.prototype._onScriptElementAdded = function (script) { var _this = this; var scriptSrc = nativeMethods$1.scriptSrcGetter.call(script); if (scriptSrc === void 0 || scriptSrc === '') return; this.emit(SCRIPT_ADDED, script); var done = function () { nativeMethods$1.removeEventListener.call(script, 'load', done); nativeMethods$1.removeEventListener.call(script, 'error', done); _this.emit(SCRIPT_LOADED_OR_FAILED, script); }; nativeMethods$1.addEventListener.call(script, 'load', done); nativeMethods$1.addEventListener.call(script, 'error', done); }; HammerheadScriptExecutionEmitter.prototype.onScriptAdded = function (listener) { this.on(SCRIPT_ADDED, listener); }; HammerheadScriptExecutionEmitter.prototype.onScriptLoadedOrFailed = function (listener) { this.on(SCRIPT_LOADED_OR_FAILED, listener); }; HammerheadScriptExecutionEmitter.prototype.offAll = function () { _super.prototype.offAll.call(this); hammerhead__default.off(hammerhead__default.EVENTS.scriptElementAdded, this._onScriptElementAdded); }; return HammerheadScriptExecutionEmitter; }(EventEmitter)); var Promise = hammerhead__default.Promise; var nativeMethods$2 = hammerhead__default.nativeMethods; function delay$2 (ms) { return new Promise(function (resolve) { return nativeMethods$2.setTimeout.call(window, resolve, ms); }); } var Promise$1 = hammerhead__default.Promise; var nativeMethods$3 = hammerhead__default.nativeMethods; var listeners$1 = hammerhead__default.eventSandbox.listeners; var browserUtils$2 = hammerhead__default.utils.browser; // Imported form the hammerhead var BUTTON = hammerhead__default.utils.event.BUTTON; var BUTTONS_PARAMETER = hammerhead__default.utils.event.BUTTONS_PARAMETER; var DOM_EVENTS = hammerhead__default.utils.event.DOM_EVENTS; var WHICH_PARAMETER = hammerhead__default.utils.event.WHICH_PARAMETER; var preventDefault = hammerhead__default.utils.event.preventDefault; function bind(el, event, handler, useCapture) { if (browserUtils$2.isIE11 && isWindow(el)) nativeMethods$3.windowAddEventListener.call(el, event, handler, useCapture); else nativeMethods$3.addEventListener.call(el, event, handler, useCapture); } function unbind(el, event, handler, useCapture) { if (browserUtils$2.isIE11 && isWindow(el)) nativeMethods$3.windowRemoveEventListener.call(el, event, handler, useCapture); else nativeMethods$3.removeEventListener.call(el, event, handler, useCapture); } // Document ready var waitForDomContentLoaded = function () { // NOTE: We can't use a regular Promise here, because window.load event can happen in the same event loop pass // The default Promise will call resolve handlers in the next pass, and load event will be lost. var resolveHandlers = []; function createPromiseResolver(resolveHandler) { return new Promise$1(function (resolve) { return resolveHandlers.push(function () { return resolve(resolveHandler()); }); }); } var isReady = false; function ready() { if (isReady) return; if (!document.body) { nativeMethods$3.setTimeout.call(window, ready, 1); return; } isReady = true; resolveHandlers.forEach(function (handler) { return handler(); }); } function onContentLoaded() { if (!isIFrameWindowInDOM(window) && !isTopWindow(window)) return; unbind(document, 'DOMContentLoaded', onContentLoaded); ready(); } if (document.readyState === 'complete') nativeMethods$3.setTimeout.call(window, onContentLoaded, 1); else bind(document, 'DOMContentLoaded', onContentLoaded); return { then: function (handler) { return createPromiseResolver(handler); } }; }; var waitForWindowLoad = function () { return new Promise$1(function (resolve) { return bind(window, 'load', resolve); }); }; function documentReady(pageLoadTimeout) { if (pageLoadTimeout === void 0) { pageLoadTimeout = 0; } return waitForDomContentLoaded() .then(function () { if (!listeners$1.getEventListeners(window, 'load').length) return null; return Promise$1.race([waitForWindowLoad(), delay$2(pageLoadTimeout)]); }); } var eventUtils = /*#__PURE__*/Object.freeze({ __proto__: null, BUTTON: BUTTON, BUTTONS_PARAMETER: BUTTONS_PARAMETER, DOM_EVENTS: DOM_EVENTS, WHICH_PARAMETER: WHICH_PARAMETER, preventDefault: preventDefault, bind: bind, unbind: unbind, documentReady: documentReady }); var ClientMessages; (function (ClientMessages) { ClientMessages["ready"] = "ready"; ClientMessages["readyForBrowserManipulation"] = "ready-for-browser-manipulation"; ClientMessages["waitForFileDownload"] = "wait-for-file-download"; })(ClientMessages || (ClientMessages = {})); var MESSAGE = ClientMessages; var Promise$2 = hammerhead__default.Promise; var browserUtils$3 = hammerhead__default.utils.browser; var nativeMethods$4 = hammerhead__default.nativeMethods; var transport = hammerhead__default.transport; var DEFAULT_BARRIER_TIMEOUT = 400; var SHORT_WAIT_FOR_UNLOAD_TIMEOUT = 30; var FILE_DOWNLOAD_CHECK_DELAY = 500; var MAX_UNLOADING_TIMEOUT = 15000; var unloading = false; var pageNavigationTriggeredListener = null; var pageNavigationTriggered = false; function onBeforeUnload() { if (browserUtils$3.isIE) { prolongUnloadWaitingIeOnly(SHORT_WAIT_FOR_UNLOAD_TIMEOUT); exceptFileDownloadingIeOnly(); return; } unloading = true; } // NOTE: this variables are for IE only var waitingForUnload = false; var waitingForUnloadTimeoutId = null; var waitingPromiseResolvers = []; function prolongUnloadWaitingIeOnly(timeout) { if (waitingForUnloadTimeoutId) nativeMethods$4.clearTimeout.call(window, waitingForUnloadTimeoutId); waitingForUnload = true; waitingForUnloadTimeoutId = nativeMethods$4.setTimeout.call(window, function () { waitingForUnloadTimeoutId = null; waitingForUnload = false; waitingPromiseResolvers.forEach(function (resolve) { return resolve(); }); waitingPromiseResolvers = []; }, timeout); } function exceptFileDownloadingIeOnly() { delay$2(0) .then(function () { // NOTE: except file downloading if (document.readyState === 'loading') { var activeElement = nativeMethods$4.documentActiveElementGetter.call(document); if (!activeElement || !isAnchorElement(activeElement) || !activeElement.hasAttribute('download')) unloading = true; } }); } function waitForFileDownload() { return delay$2(FILE_DOWNLOAD_CHECK_DELAY) .then(function () { return transport.queuedAsyncServiceMsg({ cmd: MESSAGE.waitForFileDownload }); }) // eslint-disable-next-line consistent-return .then(function (fileDownloadingHandled) { // NOTE: we use a flag to confirm file download because if unload // is raised the browser can respond with an empty string if (!fileDownloadingHandled) return Promise$2(function () { }); }); } // API function init() { hammerhead__default.on(hammerhead__default.EVENTS.beforeUnload, onBeforeUnload); bind(window, 'unload', function () { unloading = true; }); } function watchForPageNavigationTriggers() { pageNavigationTriggeredListener = function () { pageNavigationTriggered = true; }; hammerhead__default.on(hammerhead__default.EVENTS.pageNavigationTriggered, pageNavigationTriggeredListener); } function wait(timeout) { if (timeout === void 0) timeout = !pageNavigationTriggeredListener || pageNavigationTriggered ? DEFAULT_BARRIER_TIMEOUT : 0; if (pageNavigationTriggeredListener) { hammerhead__default.off(hammerhead__default.EVENTS.pageNavigationTriggered, pageNavigationTriggeredListener); pageNavigationTriggeredListener = null; } var waitForUnloadingPromise = delay$2(timeout) // eslint-disable-next-line consistent-return .then(function () { if (unloading) { return waitForFileDownload() .then(function () { unloading = false; }); } if (waitingForUnload) return new Promise$2(function (resolve) { return waitingPromiseResolvers.push(resolve); }); }); // NOTE: sometimes the page isn't actually unloaded after the beforeunload event // fires (see issues #664, #437). To avoid test hanging, we resolve the unload // barrier waiting promise in MAX_UNLOADING_TIMEOUT. We can improve this logic when // the https://github.com/DevExpress/testcafe-hammerhead/issues/667 issue is fixed. var watchdog = delay$2(MAX_UNLOADING_TIMEOUT) .then(function () { unloading = false; }); return Promise$2.race([waitForUnloadingPromise, watchdog]); } var pageUnloadBarrier = /*#__PURE__*/Object.freeze({ __proto__: null, init: init, watchForPageNavigationTriggers: watchForPageNavigationTriggers, wait: wait }); // @ts-ignore var adapter$1 = {}; function initializeAdapter$2(initializer) { if (initializer.nativeMethods.objectAssign) { initializer.nativeMethods.objectAssign(adapter$1, initializer); return; } var keys = initializer.nativeMethods.objectKeys(initializer); for (var _i = 0, keys_1 = keys; _i < keys_1.length; _i++) { var key = keys_1[_i]; // @ts-ignore adapter$1[key] = initializer[key]; } } var isVisibilityHiddenNode = function (node) { return !!adapter$1.dom.findParent(node, true, function (ancestor) { return adapter$1.dom.isElementNode(ancestor) && adapter$1.style.get(ancestor, 'visibility') === 'hidden'; }); }; var isHiddenNode = function (node) { return !!adapter$1.dom.findParent(node, true, function (ancestor) { return adapter$1.dom.isElementNode(ancestor) && adapter$1.style.get(ancestor, 'display') === 'none'; }); }; function isNotVisibleNode(node) { return !adapter$1.dom.isRenderedNode(node) || isHiddenNode(node) || isVisibilityHiddenNode(node); } function hasDimensions(el) { //NOTE: it's like jquery ':visible' selector (http://blog.jquery.com/2009/02/20/jquery-1-3-2-released/) return el && !(el.offsetHeight <= 0 && el.offsetWidth <= 0); } function isFixedElement(node) { return adapter$1.dom.isElementNode(node) && adapter$1.style.get(node, 'position') === 'fixed'; } var AxisValues = /** @class */ (function () { function AxisValues(x, y) { this.x = x; this.y = y; } AxisValues.create = function (a) { if ('left' in a) return new AxisValues(a.left, a.top); else if ('right' in a) return new AxisValues(a.right, a.bottom); return new AxisValues(a.x, a.y); }; AxisValues.prototype.add = function (p) { this.x += p.x; this.y += p.y; return this; }; AxisValues.prototype.sub = function (p) { this.x -= p.x; this.y -= p.y; return this; }; AxisValues.prototype.round = function (fn) { if (fn === void 0) { fn = Math.round; } this.x = fn(this.x); this.y = fn(this.y); return this; }; AxisValues.prototype.eql = function (p) { return this.x === p.x && this.y === p.y; }; AxisValues.prototype.mul = function (n) { this.x *= n; this.y *= n; return this; }; return AxisValues; }()); var SCROLLABLE_OVERFLOW_STYLE_RE = /auto|scroll/i; var DEFAULT_IE_SCROLLABLE_OVERFLOW_STYLE_VALUE = 'visible'; function getScrollable(el) { var overflowX = adapter$1.style.get(el, 'overflowX'); var overflowY = adapter$1.style.get(el, 'overflowY'); var scrollableHorizontally = SCROLLABLE_OVERFLOW_STYLE_RE.test(overflowX); var scrollableVertically = SCROLLABLE_OVERFLOW_STYLE_RE.test(overflowY); // IE11 and MS Edge bug: There are two properties: overflow-x and overflow-y. // If one property is set so that the browser may show scrollbars (`auto` or `scroll`) and the second one is set to 'visible', // then the second one will work as if it had the 'auto' value. if (adapter$1.browser.isIE) { scrollableHorizontally = scrollableHorizontally || scrollableVertically && overflowX === DEFAULT_IE_SCROLLABLE_OVERFLOW_STYLE_VALUE; scrollableVertically = scrollableVertically || scrollableHorizontally && overflowY === DEFAULT_IE_SCROLLABLE_OVERFLOW_STYLE_VALUE; } return new AxisValues(scrollableHorizontally, scrollableVertically); } function hasBodyScroll(el) { var overflowX = adapter$1.style.get(el, 'overflowX'); var overflowY = adapter$1.style.get(el, 'overflowY'); var scrollableHorizontally = SCROLLABLE_OVERFLOW_STYLE_RE.test(overflowX); var scrollableVertically = SCROLLABLE_OVERFLOW_STYLE_RE.test(overflowY); var documentElement = adapter$1.dom.findDocument(el).documentElement; var bodyScrollHeight = el.scrollHeight; if (adapter$1.browser.isChrome || adapter$1.browser.isFirefox) { var bodyTop = el.getBoundingClientRect().top; var documentTop = documentElement.getBoundingClientRect().top; bodyScrollHeight = bodyScrollHeight - documentTop + bodyTop; } return (scrollableHorizontally || scrollableVertically) && bodyScrollHeight > documentElement.scrollHeight; } function hasHTMLElementScroll(el) { var overflowX = adapter$1.style.get(el, 'overflowX'); var overflowY = adapter$1.style.get(el, 'overflowY'); //T303226 if (overflowX === 'hidden' && overflowY === 'hidden') return false; var hasHorizontalScroll = el.scrollHeight > el.clientHeight; var hasVerticalScroll = el.scrollWidth > el.clientWidth; if (hasHorizontalScroll || hasVerticalScroll) return true; //T174562 - wrong scrolling in iframes without src and others iframes var body = el.getElementsByTagName('body')[0]; if (!body) return false; if (hasBodyScroll(body)) return false; var clientWidth = Math.min(el.clientWidth, body.clientWidth); var clientHeight = Math.min(el.clientHeight, body.clientHeight); return body.scrollHeight > clientHeight || body.scrollWidth > clientWidth; } function hasScroll(el) { if (adapter$1.dom.isBodyElement(el)) return hasBodyScroll(el); if (adapter$1.dom.isHtmlElement(el)) return hasHTMLElementScroll(el); var scrollable = getScrollable(el); if (!scrollable.x && !scrollable.y) return false; var hasVerticalScroll = scrollable.y && el.scrollHeight > el.clientHeight; var hasHorizontalScroll = scrollable.x && el.scrollWidth > el.clientWidth; return hasHorizontalScroll || hasVerticalScroll; } function getScrollableParents(element) { var parentsArray = adapter$1.dom.getParents(element); if (adapter$1.dom.isElementInIframe(element)) { var iframe = adapter$1.dom.getIframeByElement(element); if (iframe) { var iFrameParents = adapter$1.dom.getParents(iframe); parentsArray.concat(iFrameParents); } } return adapter$1.nativeMethods.arrayFilter.call(parentsArray, hasScroll); } var scrollUtils = /*#__PURE__*/Object.freeze({ __proto__: null, hasScroll: hasScroll, getScrollableParents: getScrollableParents }); var styleUtils = hammerhead__default.utils.style; var getBordersWidth = hammerhead__default.utils.style.getBordersWidth; var getComputedStyle = hammerhead__default.utils.style.getComputedStyle; var getElementMargin = hammerhead__default.utils.style.getElementMargin; var getElementPadding = hammerhead__default.utils.style.getElementPadding; var getElementScroll = hammerhead__default.utils.style.getElementScroll; var getOptionHeight = hammerhead__default.utils.style.getOptionHeight; var getSelectElementSize = hammerhead__default.utils.style.getSelectElementSize; var isElementVisible = hammerhead__default.utils.style.isElementVisible; var isSelectVisibleChild = hammerhead__default.utils.style.isVisibleChild; var getWidth = hammerhead__default.utils.style.getWidth; var getHeight = hammerhead__default.utils.style.getHeight; var getInnerWidth = hammerhead__default.utils.style.getInnerWidth; var getInnerHeight = hammerhead__default.utils.style.getInnerHeight; var getScrollLeft = hammerhead__default.utils.style.getScrollLeft; var getScrollTop = hammerhead__default.utils.style.getScrollTop; var setScrollLeft = hammerhead__default.utils.style.setScrollLeft; var setScrollTop = hammerhead__default.utils.style.setScrollTop; var get = hammerhead__default.utils.style.get; function set(el, style, value) { if (typeof style === 'string') styleUtils.set(el, style, value); for (var property in style) { if (style.hasOwnProperty(property)) styleUtils.set(el, property, style[property]); } } function getViewportDimension(windowDimension, documentDimension, bodyDimension) { if (documentDimension > windowDimension) return bodyDimension; if (bodyDimension > windowDimension) return documentDimension; return Math.max(bodyDimension, documentDimension); } function getViewportDimensions() { return { width: getViewportDimension(window.innerWidth, document.documentElement.clientWidth, document.body.clientWidth), height: getViewportDimension(window.innerHeight, document.documentElement.clientHeight, document.body.clientHeight), }; } var styleUtils$1 = /*#__PURE__*/Object.freeze({ __proto__: null, getBordersWidth: getBordersWidth, getComputedStyle: getComputedStyle, getElementMargin: getElementMargin, getElementPadding: getElementPadding, getElementScroll: getElementScroll, getOptionHeight: getOptionHeight, getSelectElementSize: getSelectElementSize, isElementVisible: isElementVisible, isSelectVisibleChild: isSelectVisibleChild, getWidth: getWidth, getHeight: getHeight, getInnerWidth: getInnerWidth, getInnerHeight: getInnerHeight, getScrollLeft: getScrollLeft, getScrollTop: getScrollTop, setScrollLeft: setScrollLeft, setScrollTop: setScrollTop, get: get, set: set, getViewportDimensions: getViewportDimensions, hasScroll: hasScroll, isNotVisibleNode: isNotVisibleNode, hasDimensions: hasDimensions, isFixedElement: isFixedElement }); var browserUtils$4 = hammerhead.utils.browser; var listeners$2 = hammerhead.eventSandbox.listeners; var eventSimulator = hammerhead.eventSandbox.eventSimulator; var PREVENTED_EVENTS = [ 'click', 'mousedown', 'mouseup', 'dblclick', 'contextmenu', 'mousemove', 'mouseover', 'mouseout', 'touchstart', 'touchmove', 'touchend', 'keydown', 'keypress', 'input', 'keyup', 'change', 'focus', 'blur', 'MSPointerDown', 'MSPointerMove', 'MSPointerOver', 'MSPointerOut', 'MSPointerUp', 'pointerdown', 'pointermove', 'pointerover', 'pointerout', 'pointerup', ]; var F12_KEY_CODE = 123; function checkBrowserHotkey(e) { // NOTE: Opening browser tools with F12, CTRL+SHIFT+The
uglifyjs
CLI command executed orminify()
options used.https://github.com/DevExpress/testcafe/blob/master/Gulpfile.js#L197
Also reproducible here: https://skalman.github.io/UglifyJS-online/
JavaScript output or error produced.
Produced errror at runtime:
TypeError: Failed to construct 'Promise': Please use the 'new' operator, this object constructor cannot be called as a function.
.The error in the generated code:
This part:
Gets transformed to this:
And then further down:
The error being this:
if (!e) return Nt(function () {});
-Nt
is being called without thenew
constructor.Context: https://github.com/DevExpress/testcafe/issues/6624