diff --git a/lib/browser/api/browser-view.ts b/lib/browser/api/browser-view.ts index ed6670d4574..dc6b3818e78 100644 --- a/lib/browser/api/browser-view.ts +++ b/lib/browser/api/browser-view.ts @@ -68,10 +68,7 @@ export default class BrowserView { // a webContents can be closed by the user while the BrowserView // remains alive and attached to a BrowserWindow. set ownerWindow (w: BrowserWindow | null) { - if (this.#ownerWindow && this.#resizeListener) { - this.#ownerWindow.off('resize', this.#resizeListener); - this.#resizeListener = null; - } + this.#removeResizeListener(); if (this.webContents && !this.webContents.isDestroyed()) { this.webContents._setOwnerWindow(w); @@ -82,6 +79,7 @@ export default class BrowserView { this.#lastWindowSize = w.getBounds(); w.on('resize', this.#resizeListener = this.#autoResize.bind(this)); w.on('closed', () => { + this.#removeResizeListener(); this.#ownerWindow = null; this.#destroyListener = null; }); @@ -94,6 +92,13 @@ export default class BrowserView { this.#ownerWindow?.contentView.removeChildView(this.webContentsView); } + #removeResizeListener () { + if (this.#ownerWindow && this.#resizeListener) { + this.#ownerWindow.off('resize', this.#resizeListener); + this.#resizeListener = null; + } + } + #autoHorizontalProportion: {width: number, left: number} | null = null; #autoVerticalProportion: {height: number, top: number} | null = null; #autoResize () {