Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: browserView.webContents can be null #40569

Open
wants to merge 10 commits into
base: main
Choose a base branch
from
2 changes: 1 addition & 1 deletion docs/api/browser-view.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Objects created with `new BrowserView` have the following properties:

#### `view.webContents` _Experimental_

A [`WebContents`](web-contents.md) object owned by this view.
A `WebContents | null` property that returns the `WebContents` owned by this view or `null` if the contents are [destroyed](web-contents.md#event-destroyed).

### Instance Methods

Expand Down
4 changes: 3 additions & 1 deletion lib/browser/api/browser-window.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,9 @@ BrowserWindow.fromWebContents = (webContents: WebContents) => {
};

BrowserWindow.fromBrowserView = (browserView: BrowserView) => {
return BrowserWindow.fromWebContents(browserView.webContents);
const { webContents } = browserView;
if (!webContents) return null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you'll need to update the docs for BrowserWindow.fromBrowserView to state that it can return null, too.

return BrowserWindow.fromWebContents(webContents);
};

BrowserWindow.prototype.setTouchBar = function (touchBar) {
Expand Down