Skip to content

Commit

Permalink
feat: deprecate desktopCapturer.getSources in the renderer (#30721)
Browse files Browse the repository at this point in the history
  • Loading branch information
nornagon committed Sep 2, 2021
1 parent 6d4995e commit ee0e15a
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
42 changes: 42 additions & 0 deletions docs/breaking-changes.md
Expand Up @@ -12,6 +12,39 @@ This document uses the following convention to categorize breaking changes:
* **Deprecated:** An API was marked as deprecated. The API will continue to function, but will emit a deprecation warning, and will be removed in a future release.
* **Removed:** An API or feature was removed, and is no longer supported by Electron.

## Planned Breaking API Changes (17.0)

### Removed: `desktopCapturer.getSources` in the renderer

The `desktopCapturer.getSources` API is now only available in the main process.
This has been changed in order to improve the default security of Electron
apps.

If you need this functionality, it can be replaced as follows:

```js
// Main process
const { ipcMain, desktopCapturer } = require('electron')

ipcMain.handle(
'DESKTOP_CAPTURER_GET_SOURCES',
(event, opts) => desktopCapturer.getSources(opts)
)
```

```js
// Renderer process
const { ipcRenderer } = require('electron')

const desktopCapturer = {
getSources: (opts) => ipcRenderer.invoke('DESKTOP_CAPTURER_GET_SOURCES', opts)
}
```

However, you should consider further restricting the information returned to
the renderer; for instance, displaying a source selector to the user and only
returning the selected source.

## Planned Breaking API Changes (16.0)

### Behavior Changed: `crashReporter` implementation switched to Crashpad on Linux
Expand All @@ -27,6 +60,15 @@ Linux, including that long values will no longer be split between annotations
appended with `__1`, `__2` and so on, and instead will be truncated at the
(new, longer) annotation value limit.

### Deprecated: `desktopCapturer.getSources` in the renderer

Usage of the `desktopCapturer.getSources` API in the renderer has been
deprecated and will be removed. This change improves the default security of
Electron apps.

See [here](#removed-desktopcapturergetsources-in-the-renderer) for details on
how to replace this API in your app.

## Planned Breaking API Changes (14.0)

### Removed: `remote` module
Expand Down
6 changes: 6 additions & 0 deletions lib/renderer/api/desktop-capturer.ts
@@ -1,5 +1,6 @@
import { ipcRendererInternal } from '@electron/internal/renderer/ipc-renderer-internal';
import { deserialize } from '@electron/internal/common/type-utils';
import deprecate from '@electron/internal/common/api/deprecate';
import { IPC_MESSAGES } from '@electron/internal/common/ipc-messages';

const { hasSwitch } = process._linkedBinding('electron_common_command_line');
Expand All @@ -14,6 +15,11 @@ function getCurrentStack () {
return (target as any).stack;
}

let warned = process.noDeprecation;
export async function getSources (options: Electron.SourcesOptions) {
if (!warned) {
deprecate.log('The use of \'desktopCapturer.getSources\' in the renderer process is deprecated and will be removed. See https://www.electronjs.org/docs/breaking-changes#removed-desktopcapturergetsources-in-the-renderer for more details.');
warned = true;
}
return deserialize(await ipcRendererInternal.invoke(IPC_MESSAGES.DESKTOP_CAPTURER_GET_SOURCES, options, getCurrentStack()));
}

0 comments on commit ee0e15a

Please sign in to comment.