From b9574c32e7c6a8f9820c34000d1ef6a5d25b8759 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 9b6f932e1a529..3d9b28fa2fe4f 100644 --- a/lib/browser/api/web-contents.ts +++ b/lib/browser/api/web-contents.ts @@ -503,6 +503,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;