Browse Source

fix: ensure the webContents is not destroyed before communicating (#18487)

trop[bot] 5 years ago
parent
commit
335178098d
1 changed files with 5 additions and 3 deletions
  1. 5 3
      lib/browser/chrome-extension.js

+ 5 - 3
lib/browser/chrome-extension.js

@@ -118,7 +118,9 @@ const removeBackgroundPages = function (manifest) {
 
 const sendToBackgroundPages = function (...args) {
   for (const page of Object.values(backgroundPages)) {
-    page.webContents._sendInternalToAll(...args)
+    if (!page.webContents.isDestroyed()) {
+      page.webContents._sendInternalToAll(...args)
+    }
   }
 }
 
@@ -164,7 +166,7 @@ ipcMainUtils.handle('CHROME_RUNTIME_CONNECT', function (event, extensionId, conn
   }
 
   const page = backgroundPages[extensionId]
-  if (!page) {
+  if (!page || page.webContents.isDestroyed()) {
     throw new Error(`Connect to unknown extension ${extensionId}`)
   }
 
@@ -194,7 +196,7 @@ ipcMainUtils.handle('CHROME_RUNTIME_SEND_MESSAGE', async function (event, extens
   }
 
   const page = backgroundPages[extensionId]
-  if (!page) {
+  if (!page || page.webContents.isDestroyed()) {
     throw new Error(`Connect to unknown extension ${extensionId}`)
   }