fix: potentially closed webContents in BrowserView (#42811)

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
trop[bot] 2024-07-10 11:18:17 -04:00 committed by GitHub
parent 06308d8f23
commit 474c4b43db
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 107 additions and 21 deletions

View file

@ -222,7 +222,9 @@ BrowserWindow.prototype.removeBrowserView = function (browserView: BrowserView)
};
BrowserWindow.prototype.getBrowserView = function () {
if (this._browserViews.length > 1) { throw new Error('This BrowserWindow has multiple BrowserViews, use getBrowserViews() instead'); }
if (this._browserViews.length > 1) {
throw new Error('This BrowserWindow has multiple BrowserViews - use getBrowserViews() instead');
}
return this._browserViews[0] ?? null;
};
@ -231,7 +233,9 @@ BrowserWindow.prototype.getBrowserViews = function () {
};
BrowserWindow.prototype.setTopBrowserView = function (browserView: BrowserView) {
if (browserView.ownerWindow !== this) { throw new Error('Given BrowserView is not attached to the window'); }
if (browserView.ownerWindow !== this) {
throw new Error('Given BrowserView is not attached to the window');
}
const idx = this._browserViews.indexOf(browserView);
if (idx >= 0) {
this.contentView.addChildView(browserView.webContentsView);