Skip to content

Commit

Permalink
fix: BrowserWindow.fromWebContents() can return null
Browse files Browse the repository at this point in the history
  • Loading branch information
miniak committed Aug 28, 2019
1 parent 27ce6a9 commit 92e48d4
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 2 additions & 1 deletion docs/api/browser-window.md
Expand Up @@ -658,7 +658,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)`

Expand Down
2 changes: 2 additions & 0 deletions lib/browser/api/browser-window.js
Expand Up @@ -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) => {
Expand Down
4 changes: 2 additions & 2 deletions spec-main/api-browser-window-spec.ts
Expand Up @@ -1307,10 +1307,10 @@ describe('BrowserWindow module', () => {
expect(found.id).to.equal(w.id)
})

it('returns undefined for webContents without a BrowserWindow', () => {
it('returns null for webContents without a BrowserWindow', () => {
const contents = (webContents as any).create({})
try {
expect(BrowserWindow.fromWebContents(contents)).to.be.undefined('BrowserWindow.fromWebContents(contents)')
expect(BrowserWindow.fromWebContents(contents)).to.be.null('BrowserWindow.fromWebContents(contents)')
} finally {
contents.destroy()
}
Expand Down

0 comments on commit 92e48d4

Please sign in to comment.