static getElementSelection(element) {
        const position = {};

        let isSelectionStartUndefined;
        try {
            isSelectionStartUndefined = this.isUndefined(element.selectionStart);
        } catch (error) {
            isSelectionStartUndefined = false;
        }

        try {
            if (isSelectionStartUndefined) {
                const selection = window.getSelection();
                const selectionInfo = selection.getRangeAt(0);
                position.start = selectionInfo.startOffset;
                position.end = selectionInfo.endOffset;
                position.length = position.end - position.start;
            } else {
                position.start = element.selectionStart;
                position.end = element.selectionEnd;
                position.length = position.end - position.start;
            }
        } catch (error) {
            // Manages the cases where :
            // - the 'contenteditable' elements that have no selections
            // - the <input> element is of type 'hidden'
            position.start = 0;
            position.end = 0;
            position.length = 0;
        }

        return position;
    }
Cross browser routine for getting selected range/cursor position.
Note: this also works with edge cases like contenteditable-enabled elements, and hidden inputs.

@param {HTMLInputElement|EventTarget} element
@returns {{}}