Bug 1576492 - Wait for windows to load before returning from windows.getCurrent and .getLastFocused. r=mkmelin DONTBUILD
authorGeoff Lankow <geoff@darktrojan.net>
Wed, 04 Sep 2019 21:41:15 +1200
changeset 27503 d7405123c5b226c9eb3bb553c06ddf00f8355f24
parent 27502 4d2a7b8c0355acc0e5a6995aa08d6da95518413f
child 27504 a2b37e328ee04727fff731546f53e0bedd8b876e
push id16363
push usermozilla@jorgk.com
push dateWed, 04 Sep 2019 09:55:58 +0000
treeherdercomm-central@d7405123c5b2 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmkmelin
bugs1576492
Bug 1576492 - Wait for windows to load before returning from windows.getCurrent and .getLastFocused. r=mkmelin DONTBUILD
mail/components/extensions/parent/ext-windows.js
--- a/mail/components/extensions/parent/ext-windows.js
+++ b/mail/components/extensions/parent/ext-windows.js
@@ -103,24 +103,34 @@ this.windows = class extends ExtensionAP
           if (!window) {
             return Promise.reject({
               message: `Invalid window ID: ${windowId}`,
             });
           }
           return Promise.resolve(windowManager.convert(window, getInfo));
         },
 
-        getCurrent(getInfo) {
+        async getCurrent(getInfo) {
           let window = context.currentWindow || windowTracker.topWindow;
-          return Promise.resolve(windowManager.convert(window, getInfo));
+          if (window.document.readyState != "complete") {
+            await new Promise(resolve =>
+              window.addEventListener("load", resolve, { once: true })
+            );
+          }
+          return windowManager.convert(window, getInfo);
         },
 
-        getLastFocused(getInfo) {
+        async getLastFocused(getInfo) {
           let window = windowTracker.topWindow;
-          return Promise.resolve(windowManager.convert(window, getInfo));
+          if (window.document.readyState != "complete") {
+            await new Promise(resolve =>
+              window.addEventListener("load", resolve, { once: true })
+            );
+          }
+          return windowManager.convert(window, getInfo);
         },
 
         getAll(getInfo) {
           let doNotCheckTypes = !getInfo || !getInfo.windowTypes;
 
           let windows = Array.from(windowManager.getAll(), win =>
             win.convert(getInfo)
           ).filter(