From 7e52db4e18c8e018e40ba823df0a6fc9f29ee615 Mon Sep 17 00:00:00 2001 From: Milan Burda Date: Thu, 10 Jan 2019 23:59:44 +0100 Subject: [PATCH] fix: BrowserWindow.fromWebContents() can return null --- docs/api/browser-window.md | 3 ++- lib/browser/api/browser-window.js | 2 ++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 66a3cdd6cc299..22176f49ebde1 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -655,7 +655,8 @@ Returns `BrowserWindow | null` - The window that is focused in this application, * `webContents` [WebContents](web-contents.md) -Returns `BrowserWindow` - The window that owns the given `webContents`. +Returns `BrowserWindow | null` - The window that owns the given `webContents` +or `null` if the contents are not owned by a window. #### `BrowserWindow.fromBrowserView(browserView)` diff --git a/lib/browser/api/browser-window.js b/lib/browser/api/browser-window.js index 939124633be7a..521414fd01bab 100644 --- a/lib/browser/api/browser-window.js +++ b/lib/browser/api/browser-window.js @@ -118,6 +118,8 @@ BrowserWindow.fromWebContents = (webContents) => { for (const window of BrowserWindow.getAllWindows()) { if (window.webContents.equal(webContents)) return window } + + return null } BrowserWindow.fromBrowserView = (browserView) => {