diff --git a/docs/tutorial/sandbox.md b/docs/tutorial/sandbox.md index 20259c92993a..b9a08e3594d3 100644 --- a/docs/tutorial/sandbox.md +++ b/docs/tutorial/sandbox.md @@ -51,6 +51,12 @@ but can only import a subset of Electron and Node's built-in modules: * [`timers`](https://nodejs.org/api/timers.html) * [`url`](https://nodejs.org/api/url.html) +[node: imports](https://nodejs.org/api/esm.html#node-imports) are supported as well: + +* [`node:events`](https://nodejs.org/api/events.html) +* [`node:timers`](https://nodejs.org/api/timers.html) +* [`node:url`](https://nodejs.org/api/url.html) + In addition, the preload script also polyfills certain Node.js primitives as globals: * [`Buffer`](https://nodejs.org/api/buffer.html) diff --git a/lib/sandboxed_renderer/init.ts b/lib/sandboxed_renderer/init.ts index 9c07a198240a..913b57480c6c 100644 --- a/lib/sandboxed_renderer/init.ts +++ b/lib/sandboxed_renderer/init.ts @@ -38,12 +38,15 @@ const loadedModules = new Map([ ['electron', electron], ['electron/common', electron], ['electron/renderer', electron], - ['events', events] + ['events', events], + ['node:events', events] ]); const loadableModules = new Map([ ['timers', () => require('timers')], - ['url', () => require('url')] + ['node:timers', () => require('timers')], + ['url', () => require('url')], + ['node:url', () => require('url')] ]); // Pass different process object to the preload script. diff --git a/spec/api-browser-window-spec.ts b/spec/api-browser-window-spec.ts index 2577cb0ec1b9..c0f931fc9e70 100644 --- a/spec/api-browser-window-spec.ts +++ b/spec/api-browser-window-spec.ts @@ -3714,6 +3714,9 @@ describe('BrowserWindow module', () => { expect(test.version).to.equal(process.version); expect(test.versions).to.deep.equal(process.versions); expect(test.contextId).to.be.a('string'); + expect(test.nodeEvents).to.equal(true); + expect(test.nodeTimers).to.equal(true); + expect(test.nodeUrl).to.equal(true); if (process.platform === 'linux' && test.osSandbox) { expect(test.creationTime).to.be.null('creation time'); diff --git a/spec/fixtures/module/preload-sandbox.js b/spec/fixtures/module/preload-sandbox.js index 051754c75b16..2b42d5198fd7 100644 --- a/spec/fixtures/module/preload-sandbox.js +++ b/spec/fixtures/module/preload-sandbox.js @@ -34,6 +34,9 @@ cpuUsage: invoke(() => process.getCPUUsage()), ioCounters: invoke(() => process.getIOCounters()), uptime: invoke(() => process.uptime()), + nodeEvents: invoke(() => require('events') === require('node:events')), + nodeTimers: invoke(() => require('timers') === require('node:timers')), + nodeUrl: invoke(() => require('url') === require('node:url')), env: process.env, execPath: process.execPath, pid: process.pid,