diff --git a/docs/api/breaking-changes.md b/docs/api/breaking-changes.md index a5db709aeab0e..ec897a1bc13aa 100644 --- a/docs/api/breaking-changes.md +++ b/docs/api/breaking-changes.md @@ -65,6 +65,39 @@ not present, then the native module will fail to load on Windows, with an error message like `Cannot find module`. See the [native module guide](/docs/tutorial/using-native-node-modules.md) for more. +## `electron.screen` in renderer process + +```js +// Deprecated +require('electron').screen +// Replace with +require('electron').remote.screen +``` + +## `require` in sandboxed renderers + +```js +// Deprecated +require('child_process') +// Replace with +require('electron').remote.require('child_process') + +// Deprecated +require('fs') +// Replace with +require('electron').remote.require('fs') + +// Deprecated +require('os') +// Replace with +require('electron').remote.require('os') + +// Deprecated +require('path') +// Replace with +require('electron').remote.require('path') +``` + # Breaking API Changes (3.0) diff --git a/lib/browser/api/app.js b/lib/browser/api/app.js index 31699e33c31a9..922c32d897f3e 100644 --- a/lib/browser/api/app.js +++ b/lib/browser/api/app.js @@ -93,9 +93,7 @@ if (process.platform === 'linux') { } app.allowNTLMCredentialsForAllDomains = function (allow) { - if (!process.noDeprecation) { - deprecate.warn('app.allowNTLMCredentialsForAllDomains', 'session.allowNTLMCredentialsForDomains') - } + deprecate.warn('app.allowNTLMCredentialsForAllDomains', 'session.allowNTLMCredentialsForDomains') const domains = allow ? '*' : '' if (!this.isReady()) { this.commandLine.appendSwitch('auth-server-whitelist', domains) diff --git a/lib/common/api/deprecate.js b/lib/common/api/deprecate.js index 7c060ba42bfb5..fc75d781f98eb 100644 --- a/lib/common/api/deprecate.js +++ b/lib/common/api/deprecate.js @@ -19,7 +19,9 @@ const deprecate = { setHandler: (handler) => { deprecationHandler = handler }, getHandler: () => deprecationHandler, warn: (oldName, newName) => { - return deprecate.log(`'${oldName}' is deprecated. Use '${newName}' instead.`) + if (!process.noDeprecation) { + deprecate.log(`'${oldName}' is deprecated. Use '${newName}' instead.`) + } }, log: (message) => { if (typeof deprecationHandler === 'function') { diff --git a/lib/renderer/api/screen.js b/lib/renderer/api/screen.js index 6cae10d3bb041..7366948d74eab 100644 --- a/lib/renderer/api/screen.js +++ b/lib/renderer/api/screen.js @@ -1,4 +1,8 @@ 'use strict' +const { deprecate } = require('electron') + +deprecate.warn(`electron.screen`, `electron.remote.screen`) + const { getRemoteForUsage } = require('@electron/internal/renderer/remote') module.exports = getRemoteForUsage('screen').screen diff --git a/lib/sandboxed_renderer/api/exports/child_process.js b/lib/sandboxed_renderer/api/exports/child_process.js index 21dfcee3af899..55bb75fb5acde 100644 --- a/lib/sandboxed_renderer/api/exports/child_process.js +++ b/lib/sandboxed_renderer/api/exports/child_process.js @@ -1,4 +1,8 @@ 'use strict' +const { deprecate } = require('electron') + +deprecate.warn(`require('child_process')`, `remote.require('child_process')`) + const { getRemoteForUsage } = require('@electron/internal/renderer/remote') module.exports = getRemoteForUsage('child_process').require('child_process') diff --git a/lib/sandboxed_renderer/api/exports/fs.js b/lib/sandboxed_renderer/api/exports/fs.js index 18afbfcb0f0d7..bf64ad660b6e5 100644 --- a/lib/sandboxed_renderer/api/exports/fs.js +++ b/lib/sandboxed_renderer/api/exports/fs.js @@ -1,4 +1,8 @@ 'use strict' +const { deprecate } = require('electron') + +deprecate.warn(`require('fs')`, `remote.require('fs')`) + const { getRemoteForUsage } = require('@electron/internal/renderer/remote') module.exports = getRemoteForUsage('fs').require('fs') diff --git a/lib/sandboxed_renderer/api/exports/os.js b/lib/sandboxed_renderer/api/exports/os.js index 4e2fe34155fe9..937d83ade0982 100644 --- a/lib/sandboxed_renderer/api/exports/os.js +++ b/lib/sandboxed_renderer/api/exports/os.js @@ -1,4 +1,8 @@ 'use strict' +const { deprecate } = require('electron') + +deprecate.warn(`require('os')`, `remote.require('os')`) + const { getRemoteForUsage } = require('@electron/internal/renderer/remote') module.exports = getRemoteForUsage('os').require('os') diff --git a/lib/sandboxed_renderer/api/exports/path.js b/lib/sandboxed_renderer/api/exports/path.js index f7903dc4de981..41f2c32f860c4 100644 --- a/lib/sandboxed_renderer/api/exports/path.js +++ b/lib/sandboxed_renderer/api/exports/path.js @@ -1,4 +1,8 @@ 'use strict' +const { deprecate } = require('electron') + +deprecate.warn(`require('path')`, `remote.require('path')`) + const { getRemoteForUsage } = require('@electron/internal/renderer/remote') module.exports = getRemoteForUsage('path').require('path') diff --git a/lib/sandboxed_renderer/init.js b/lib/sandboxed_renderer/init.js index 0512cf5359bf2..c46565220adc3 100644 --- a/lib/sandboxed_renderer/init.js +++ b/lib/sandboxed_renderer/init.js @@ -90,6 +90,15 @@ Object.assign(preloadProcess, processProps) Object.assign(process, binding.process) Object.assign(process, processProps) +Object.defineProperty(preloadProcess, 'noDeprecation', { + get () { + return process.noDeprecation + }, + set (value) { + process.noDeprecation = value + } +}) + process.on('exit', () => preloadProcess.emit('exit')) // This is the `require` function that will be visible to the preload script diff --git a/spec/api-browser-window-spec.js b/spec/api-browser-window-spec.js index b0b3d2a6d93eb..f0d129de9ec46 100644 --- a/spec/api-browser-window-spec.js +++ b/spec/api-browser-window-spec.js @@ -11,8 +11,8 @@ const http = require('http') const { closeWindow } = require('./window-helpers') const { emittedOnce } = require('./events-helpers') const { resolveGetters } = require('./assert-helpers') -const { ipcRenderer, remote, screen } = require('electron') -const { app, ipcMain, BrowserWindow, BrowserView, protocol, session, webContents } = remote +const { ipcRenderer, remote } = require('electron') +const { app, ipcMain, BrowserWindow, BrowserView, protocol, session, screen, webContents } = remote const features = process.atomBinding('features') const { expect } = chai diff --git a/spec/api-desktop-capturer-spec.js b/spec/api-desktop-capturer-spec.js index 42377df3e82a7..a74a2ac2aacdf 100644 --- a/spec/api-desktop-capturer-spec.js +++ b/spec/api-desktop-capturer-spec.js @@ -1,6 +1,7 @@ const chai = require('chai') const dirtyChai = require('dirty-chai') -const { desktopCapturer, remote, screen } = require('electron') +const { desktopCapturer, remote } = require('electron') +const { screen } = remote const features = process.atomBinding('features') const { expect } = chai diff --git a/spec/api-screen-spec.js b/spec/api-screen-spec.js index cf351bf1018b3..39637968f7cda 100644 --- a/spec/api-screen-spec.js +++ b/spec/api-screen-spec.js @@ -1,5 +1,5 @@ const assert = require('assert') -const { screen } = require('electron') +const { screen } = require('electron').remote describe('screen module', () => { describe('screen.getCursorScreenPoint()', () => {