Browse Source

fix: add isDestroyed check (#31208)

* Added isDestroyed check

fix: https://github.com/electron/electron/issues/31196

* fix: unregister frame name

Unregister the frame name so that we do not accidentally unregister the wrong window later on in case there is a timing issue with the events

* fix; check if webContents is destroyed

* fix: check if window/webContents is destroyed

Co-authored-by: Cheng Zhao <[email protected]>

Co-authored-by: Cheng Zhao <[email protected]>
t57ser 3 years ago
parent
commit
7eaebe0bd6
1 changed files with 7 additions and 2 deletions
  1. 7 2
      lib/browser/guest-window-manager.ts

+ 7 - 2
lib/browser/guest-window-manager.ts

@@ -65,8 +65,13 @@ export function openGuestWindow ({ event, embedder, guest, referrer, disposition
   // https://html.spec.whatwg.org/multipage/window-object.html#apis-for-creating-and-navigating-browsing-contexts-by-name
   const existingWindow = getGuestWindowByFrameName(frameName);
   if (existingWindow) {
-    existingWindow.loadURL(url);
-    return existingWindow;
+    if (existingWindow.isDestroyed() || existingWindow.webContents.isDestroyed()) {
+      // FIXME(t57ser): The webContents is destroyed for some reason, unregister the frame name
+      unregisterFrameName(frameName);
+    } else {
+      existingWindow.loadURL(url);
+      return existingWindow;
+    }
   }
 
   const window = new BrowserWindow({