diff --git a/lib/browser/api/browser-window.ts b/lib/browser/api/browser-window.ts index 605c65e2ff220..91807abd56601 100644 --- a/lib/browser/api/browser-window.ts +++ b/lib/browser/api/browser-window.ts @@ -12,6 +12,14 @@ BrowserWindow.prototype._init = function (this: BWT) { // Avoid recursive require. const { app } = require('electron'); + // Set ID at constructon time so it's accessible after + // underlying window destruction. + const id = this.id; + Object.defineProperty(this, 'id', { + value: id, + writable: false + }); + const nativeSetBounds = this.setBounds; this.setBounds = (bounds, ...opts) => { bounds = { diff --git a/spec/api-browser-window-spec.ts b/spec/api-browser-window-spec.ts index eb60852a0b9e1..98f9638317ef4 100644 --- a/spec/api-browser-window-spec.ts +++ b/spec/api-browser-window-spec.ts @@ -123,6 +123,13 @@ describe('BrowserWindow module', () => { w.webContents.on('destroyed', () => w.close()); }); + it('should allow access to id after destruction', async () => { + const closed = emittedOnce(w, 'closed'); + w.destroy(); + await closed; + expect(w.id).to.be.a('number'); + }); + it('should emit unload handler', async () => { await w.loadFile(path.join(fixtures, 'api', 'unload.html')); const closed = emittedOnce(w, 'closed');