Bug 1485157 - Check to make sure document.activeElement exists before attempting to blur it;r=Gijs
authorBrian Grinstead <bgrinstead@mozilla.com>
Tue, 04 Sep 2018 20:46:08 +0000
changeset 434783 098f6aaf52410eb6b51b230cfd2e478339d290c3
parent 434782 0db77a36565cd9971eb5794785defe498673c303
child 434784 4ad33c6fbfcad5dd5a72a1cc6a916eb49a93c6e4
push id107492
push userebalazs@mozilla.com
push dateWed, 05 Sep 2018 12:44:27 +0000
treeherdermozilla-inbound@e841c95ba671 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersGijs
bugs1485157
milestone63.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1485157 - Check to make sure document.activeElement exists before attempting to blur it;r=Gijs We're ending up in a case here where document.activeElement is null in browser.xhtml but it's a <browser> tag in browser.xul. We'll need more analysis and testing to decide if we want the HTML or XUL activeElement behavior, and then adjust as needed. But in the meantime, this unbreaks a bunch of browser.xhtml tests and is a safe null check in both cases. Differential Revision: https://phabricator.services.mozilla.com/D4705
browser/base/content/tabbrowser.js
--- a/browser/base/content/tabbrowser.js
+++ b/browser/base/content/tabbrowser.js
@@ -1089,17 +1089,19 @@ window._gBrowser = {
     } else if (gMultiProcessBrowser && activeEl != newBrowser && activeEl != newTab) {
       // In e10s, if focus isn't already in the tabstrip or on the new browser,
       // and the new browser's previous focus wasn't in the url bar but focus is
       // there now, we need to adjust focus further.
       let keepFocusOnUrlBar = newBrowser &&
         newBrowser._urlbarFocused &&
         gURLBar &&
         gURLBar.focused;
-      if (!keepFocusOnUrlBar) {
+      // In an HTML document (built with MOZ_BROWSER_XHTML), the activeElement
+      // can be null, so check before attempting to blur it (Bug 1485157).
+      if (!keepFocusOnUrlBar && document.activeElement) {
         // Clear focus so that _adjustFocusAfterTabSwitch can detect if
         // some element has been focused and respect that.
         document.activeElement.blur();
       }
     }
   },
 
   _adjustFocusAfterTabSwitch(newTab) {