Commit 834f96ac authored by Robert Knight's avatar Robert Knight

Remove various workarounds for IE 11

Remove workarounds for IE that are no longer needed since IE 11 is not
supported any more.

 - Remove optional and deprecated arguments to `document.createNodeIterator`

 - Update references to IE 11 for checks/code which is still applicable
   to other browsers

 - Remove `window.msCrypto` fallback for `window.crypto`

 - Remove unused `isIE11` helper

 - Remove IE 11 reference in `polyfills/index.js`. We don't actually
   need the check because the browser check in `boot/index.js` will fail
   if `Promise` is missing, but I left it in because that knowledge is
   contained in a separate part of the code and
   `shared/polyfills/index.js` is currently written as if it may be used
   in a pre-ES2015 environment.
parent 2abc6b6f
......@@ -26,11 +26,7 @@ export function toRange(root, start, end) {
// although optional according to the spec.
const nodeIter = root.ownerDocument.createNodeIterator(
root,
NodeFilter.SHOW_TEXT,
null, // filter
// @ts-ignore - Ignored parameter required for IE 11
false // expandEntityReferences
NodeFilter.SHOW_TEXT
);
let startContainer;
......
......@@ -102,7 +102,7 @@ function drawHighlightsAbovePdfCanvas(highlightEl) {
// @ts-ignore - `mixBlendMode` property is missing from type definitions.
svgStyle.mixBlendMode = 'multiply';
} else {
// For older browsers (IE 11, Edge < 79) we draw all the highlights as
// For older browsers (eg. Edge < 79) we draw all the highlights as
// opaque and then make the entire highlight layer transparent. This means
// that there is no visual indication of whether text has one or multiple
// highlights, but it preserves readability.
......@@ -232,7 +232,7 @@ export function highlightRange(normedRange, cssClass = 'hypothesis-highlight') {
/**
* Replace a child `node` with `replacements`.
*
* nb. This is like `ChildNode.replaceWith` but it works in IE 11.
* nb. This is like `ChildNode.replaceWith` but it works in older browsers.
*
* @param {ChildNode} node
* @param {Node[]} replacements
......
......@@ -51,11 +51,7 @@ function forEachNodeInRange(range, callback) {
// mandatory in IE although optional according to the spec.
const nodeIter = /** @type {Document} */ (root.ownerDocument).createNodeIterator(
root,
NodeFilter.SHOW_ALL,
null /* filter */,
// @ts-ignore - Deprecated last parameter. Required for IE 11.
false /* expandEntityReferences */
NodeFilter.SHOW_ALL
);
let currentNode;
......
/**
* Normalize a keyboard event key name.
*
* Several old browsers, such as IE11, use alternate key
* names for keyboard events. If any abnormal keys are used,
* this method returns the normalized name so our UI
* components don't require a special case.
* Some old Microsoft browsers, such as IE 11 and Edge Legacy [1], use non-standard
* names for some keys. If any abnormal keys are used, this method returns the
* normalized name so our UI components don't require a special case.
*
* [1] https://caniuse.com/keyboardevent-key
*
* @param {string} key - The keyboard event `key` name
* @return {string} - Normalized `key` name
......
......@@ -58,11 +58,9 @@ const needsPolyfill = {
},
es2018: () => {
if (!window.Promise) {
// IE11 does not have a Promise object.
return true;
}
return !hasMethods(Promise.prototype, 'finally');
return (
typeof Promise !== 'function' || !hasMethods(Promise.prototype, 'finally')
);
},
// Test for a fully-working URL constructor.
......
import { isIE11, isMacOS } from '../user-agent';
import { isMacOS } from '../user-agent';
describe('shared/user-agent', () => {
describe('isIE11', () => {
it('returns true when the user agent is IE 11', () => {
assert.isTrue(
isIE11('Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko')
);
});
it('returns false when the user agent is not IE 11', () => {
assert.isFalse(
isIE11(
'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/81.0.4044.92 Safari/537.36 Edg/80.0.361.109'
)
);
});
});
describe('isMacOS', () => {
it('returns true when the user agent is a Mac', () => {
assert.isTrue(
......
......@@ -2,15 +2,6 @@
* Helper methods to identify browser versions and os types
*/
/**
* Returns true when the browser is IE11.
*
* @param _userAgent {string} - Test seam
*/
export const isIE11 = (_userAgent = window.navigator.userAgent) => {
return _userAgent.indexOf('Trident/7.0') >= 0;
};
/**
* Returns true when the OS is Mac OS.
*
......
......@@ -10,9 +10,7 @@ function byteToHex(val) {
* @return {string}
*/
export function generateHexString(len) {
// @ts-ignore - TS doesn't know about `msCrypto`.
const crypto = window.crypto || window.msCrypto; /* IE 11 */
const bytes = new Uint8Array(len / 2);
crypto.getRandomValues(bytes);
window.crypto.getRandomValues(bytes);
return Array.from(bytes).map(byteToHex).join('');
}
......@@ -18,8 +18,7 @@ const maxEventsToSendPerSession = 5;
*/
function currentScriptOrigin() {
try {
// nb. IE 11 does not support `document.currentScript` and this property
// is only available while a `<script>` tag is initially being executed.
// This property is only available while a `<script>` tag is initially being executed.
const script = /** @type {HTMLScriptElement} */ (document.currentScript);
const scriptUrl = new URL(script.src);
return scriptUrl.origin;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment