Skip to content

Commit

Permalink
feat: add process.contextId used by @electron/remote
Browse files Browse the repository at this point in the history
  • Loading branch information
miniak committed Mar 4, 2021
1 parent ca75bca commit faadf85
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions docs/api/process.md
Expand Up @@ -35,6 +35,7 @@ In sandboxed renderers the `process` object contains only a subset of the APIs:
* `versions`
* `mas`
* `windowsStore`
* `contextId`

## Events

Expand Down Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions lib/renderer/init.ts
Expand Up @@ -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<string>(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;

Expand Down
3 changes: 3 additions & 0 deletions lib/sandboxed_renderer/init.ts
Expand Up @@ -89,6 +89,9 @@ Object.defineProperty(preloadProcess, 'noDeprecation', {
}
});

const contextId = v8Util.getHiddenValue<string>(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'));
Expand Down

0 comments on commit faadf85

Please sign in to comment.