From cc765bdd45cb6ea6e1350e3f9a4b9f73371e1350 Mon Sep 17 00:00:00 2001 From: "Andrew C. Dvorak" Date: Sun, 2 Sep 2018 14:22:47 -0700 Subject: [PATCH] chore(infrastructure): Workaround for Edge autofocus bug (#3498) This PR adds a [ponyfill](https://github.com/sindresorhus/ponyfill) for `autofocus` to `test/screenshot/fixture.js` as a workaround for [Edge platform issue #101198](https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/101198/): > Autofocusing does not work on first page load. Autofocusing works only after reloading the page (either by pressing F5 key, or by clicking `Refresh` button, or by focusing location bar and pressing Enter again), so effectively autofocus does not work at all. This was supposedly fixed in Edge 15, but in PR #3496, the first screenshot fails 100% of the time in Edge 17 due to a `` elements on the first page load. + * E.g.: https://storage.googleapis.com/mdc-web-screenshot-tests/advorak/2018/09/02/19_24_47_468/report/report.html + * + * This sounds suspiciously similar to an issue that was supposedly fixed in Edge 15: + * https://developer.microsoft.com/en-us/microsoft-edge/platform/issues/101198/ + * + * @private + */ + autoFocus_() { + const autoFocusEls = [].filter.call(document.querySelectorAll('[autofocus]'), (el) => { + const style = getComputedStyle(el); + if (style.visibility === 'hidden' || style.display === 'none' || style.opacity < 0.1) { + return false; + } + const rect = el.getBoundingClientRect(); + if (rect.height === 0 || rect.width === 0) { + return false; + } + return true; + }); + const autoFocusEl = autoFocusEls[0]; + if (autoFocusEl && document.activeElement !== autoFocusEl) { + autoFocusEl.focus(); + } + } + /** @private */ notifyWebDriver_() { document.body.setAttribute('data-fonts-loaded', '');