Bug 1576492 - Wait for windows to load before returning from windows.getCurrent and .getLastFocused. r=mkmelin a=jorgk
authorGeoff Lankow <geoff@darktrojan.net>
Wed, 04 Sep 2019 21:41:15 +1200
changeset 79051 7ebbba95ac1a5d7f94dbb6287c64249cf3f15d69
parent 79050 ad3c158cf10f618bfc0eec26dcddccbacf39f39c
child 79052 44c2b738b64284b7ba6ba237fc2cb377e6c1d3fa
push id9345
push userkaie@kuix.de
push dateFri, 20 Sep 2019 05:14:40 +0000
treeherdertry-comm-central@b9101c33b5e5 [default view] [failures only]
reviewersmkmelin, jorgk
bugs1576492
Bug 1576492 - Wait for windows to load before returning from windows.getCurrent and .getLastFocused. r=mkmelin a=jorgk
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(