fix: potentially closed webContents in BrowserView (#42810)

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 15:33:27 +02:00 committed by GitHub
parent 6a15e168ce
commit dc065dfa5a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 107 additions and 21 deletions

View file

@ -199,7 +199,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;
};
@ -208,7 +210,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);