From ab20c495924566072714fa8b9f56d4f95847c1d4 Mon Sep 17 00:00:00 2001 From: Jeremy Rose Date: Tue, 15 Dec 2020 17:35:25 -0800 Subject: [PATCH] fix: make webContents.id work even after destroy --- lib/browser/api/web-contents.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/lib/browser/api/web-contents.ts b/lib/browser/api/web-contents.ts index efa54d3366d06..e842487a3006d 100644 --- a/lib/browser/api/web-contents.ts +++ b/lib/browser/api/web-contents.ts @@ -528,6 +528,13 @@ WebContents.prototype._init = function () { this.goToOffset = navigationController.goToOffset.bind(navigationController); this.getActiveIndex = navigationController.getActiveIndex.bind(navigationController); this.length = navigationController.length.bind(navigationController); + // Read off the ID at construction time, so that it's accessible even after + // the underlying C++ WebContents is destroyed. + const id = this.id; + Object.defineProperty(this, 'id', { + value: id, + writable: false + }); this._windowOpenHandler = null;