Repository: electron/electron
File: lib/browser/api/browser-window.ts (TypeScript)

Code before:
BrowserWindow.prototype.inspectSharedWorker = function () {
  return this.webContents.inspectSharedWorker();
};

BrowserWindow.prototype.inspectServiceWorker = function () {
  return this.webContents.inspectServiceWorker();
};

BrowserWindow.prototype.showDefinitionForSelection = function () {
  return this.webContents.showDefinitionForSelection();
};

BrowserWindow.prototype.capturePage = function (...args) {
  return this.webContents.capturePage(...args);
};

BrowserWindow.prototype.getBackgroundThrottling = function () {
  return this.webContents.getBackgroundThrottling();
};

BrowserWindow.prototype.setBackgroundThrottling = function (allowed: boolean) {
  return this.webContents.setBackgroundThrottling(allowed);
};

BrowserWindow.prototype.addBrowserView = function (browserView: BrowserView) {
  // avoid adding the same browserView multiple times
  if (this._browserViews.includes(browserView)) {
    return;
  }
  const oldOwnerWindow = browserView.ownerWindow;
  if (oldOwnerWindow && oldOwnerWindow !== this) {
    oldOwnerWindow.removeBrowserView(browserView);
  }
  this.contentView.addChildView(browserView.webContentsView);
  browserView.ownerWindow = this;
  browserView.webContents._setOwnerWindow(this);
  this._browserViews.push(browserView);
};

BrowserWindow.prototype.setBrowserView = function (browserView: BrowserView) {
  this._browserViews.forEach(bv => {
    this.removeBrowserView(bv);
  });
  if (browserView) { this.addBrowserView(browserView); }
};

BrowserWindow.prototype.removeBrowserView = function (browserView: BrowserView) {
  const idx = this._browserViews.indexOf(browserView);
  if (idx >= 0) {
    this.contentView.removeChildView(browserView.webContentsView);
    browserView.ownerWindow = null;

Review comment (suggestion):
```suggestion
  if (this._browserViews.includes(browserView)) {
    return;
  }

  const ownerWindow = browserView.ownerWindow;
  if (ownerWindow && ownerWindow !== this) {
    ownerWindow.removeBrowserView(browserView);
  }
```

Code after:
BrowserWindow.prototype.inspectSharedWorker = function () {
  return this.webContents.inspectSharedWorker();
};

BrowserWindow.prototype.inspectServiceWorker = function () {
  return this.webContents.inspectServiceWorker();
};

BrowserWindow.prototype.showDefinitionForSelection = function () {
  return this.webContents.showDefinitionForSelection();
};

BrowserWindow.prototype.capturePage = function (...args) {
  return this.webContents.capturePage(...args);
};

BrowserWindow.prototype.getBackgroundThrottling = function () {
  return this.webContents.getBackgroundThrottling();
};

BrowserWindow.prototype.setBackgroundThrottling = function (allowed: boolean) {
  return this.webContents.setBackgroundThrottling(allowed);
};

BrowserWindow.prototype.addBrowserView = function (browserView: BrowserView) {
  if (this._browserViews.includes(browserView)) {
    return;
  }

  const ownerWindow = browserView.ownerWindow;
  if (ownerWindow && ownerWindow !== this) {
    ownerWindow.removeBrowserView(browserView);
  }
  this.contentView.addChildView(browserView.webContentsView);
  browserView.ownerWindow = this;
  browserView.webContents._setOwnerWindow(this);
  this._browserViews.push(browserView);
};

BrowserWindow.prototype.setBrowserView = function (browserView: BrowserView) {
  this._browserViews.forEach(bv => {
    this.removeBrowserView(bv);
  });
  if (browserView) { this.addBrowserView(browserView); }
};

BrowserWindow.prototype.removeBrowserView = function (browserView: BrowserView) {
  const idx = this._browserViews.indexOf(browserView);
  if (idx >= 0) {
    this.contentView.removeChildView(browserView.webContentsView);
    browserView.ownerWindow = null;