diff --git a/docs/api/process.md b/docs/api/process.md index ee00672129ff6..3f0f5e0402984 100644 --- a/docs/api/process.md +++ b/docs/api/process.md @@ -35,6 +35,7 @@ In sandboxed renderers the `process` object contains only a subset of the APIs: * `versions` * `mas` * `windowsStore` +* `contextId` ## Events @@ -133,6 +134,11 @@ A `String` representing Electron's version string. A `Boolean`. If the app is running as a Windows Store app (appx), this property is `true`, for otherwise it is `undefined`. +### `process.versions.contextId` _Readonly_ + +A `String` (optional) representing unique ID of the current JavaScript context. +This property is only available in the renderer process. + ## Methods The `process` object has the following methods: diff --git a/lib/renderer/init.ts b/lib/renderer/init.ts index c41fa561888d4..1910bd484a413 100644 --- a/lib/renderer/init.ts +++ b/lib/renderer/init.ts @@ -39,6 +39,9 @@ require('@electron/internal/common/init'); // The global variable will be used by ipc for event dispatching const v8Util = process._linkedBinding('electron_common_v8_util'); +const contextId = v8Util.getHiddenValue(global, 'contextId'); +Object.defineProperty(process, 'contextId', { get: () => contextId }); + const { ipcRendererInternal } = require('@electron/internal/renderer/ipc-renderer-internal'); const ipcRenderer = require('@electron/internal/renderer/api/ipc-renderer').default; diff --git a/lib/sandboxed_renderer/init.ts b/lib/sandboxed_renderer/init.ts index a23082ef04ad3..9d99ba01eb642 100644 --- a/lib/sandboxed_renderer/init.ts +++ b/lib/sandboxed_renderer/init.ts @@ -89,6 +89,9 @@ Object.defineProperty(preloadProcess, 'noDeprecation', { } }); +const contextId = v8Util.getHiddenValue(global, 'contextId'); +Object.defineProperty(process, 'contextId', { get: () => contextId }); + process.on('loaded', () => (preloadProcess as events.EventEmitter).emit('loaded')); process.on('exit', () => (preloadProcess as events.EventEmitter).emit('exit')); (process as events.EventEmitter).on('document-start', () => (preloadProcess as events.EventEmitter).emit('document-start'));