Browse Source

fix(desktop): avoid destroyed window permission checks (#34300)

Brendan Allan 1 tháng trước cách đây
mục cha
commit
58ba99e505
1 tập tin đã thay đổi với 4 bổ sung2 xóa
  1. 4 2
      packages/desktop/src/main/windows.ts

+ 4 - 2
packages/desktop/src/main/windows.ts

@@ -354,16 +354,18 @@ function addDocumentPolicy(response: Response, file: string) {
 }
 
 function allowRendererPermissions(win: BrowserWindow) {
+  const webContentsId = win.webContents.id
+
   win.webContents.session.setPermissionRequestHandler((webContents, permission, callback, details) => {
     callback(
       rendererPermissions.has(permission) &&
         isTrustedRendererUrl(details.requestingUrl) &&
-        webContents.id === win.webContents.id,
+        webContents.id === webContentsId,
     )
   })
   win.webContents.session.setPermissionCheckHandler((webContents, permission, requestingOrigin, details) => {
     if (!rendererPermissions.has(permission)) return false
-    if (webContents && webContents.id !== win.webContents.id) return false
+    if (webContents && webContents.id !== webContentsId) return false
     return isTrustedRendererUrl(details.requestingUrl) || isTrustedRendererUrl(requestingOrigin)
   })
 }