Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: remove outdated ipc example #37539

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
40 changes: 7 additions & 33 deletions docs/api/web-contents.md
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ cancel the request.

If no event listener is added for this event, all bluetooth requests will be cancelled.

```javascript
```javascript title='main.js'
const { app, BrowserWindow } = require('electron')

let win = null
Expand Down Expand Up @@ -1567,7 +1567,7 @@ ipcMain.on('open-devtools', (event, targetContentsId, devtoolsContentsId) => {

An example of showing devtools in a `BrowserWindow`:

```js
```js title='main.js'
const { app, BrowserWindow } = require('electron')

let win = null
Expand Down Expand Up @@ -1650,40 +1650,14 @@ Algorithm][SCA], just like [`postMessage`][], so prototype chains will not be
included. Sending Functions, Promises, Symbols, WeakMaps, or WeakSets will
throw an exception.

> **NOTE**: Sending non-standard JavaScript types such as DOM objects or
> special Electron objects will throw an exception.

The renderer process can handle the message by listening to `channel` with the
[`ipcRenderer`](ipc-renderer.md) module.

An example of sending messages from the main process to the renderer process:
:::warning

```javascript
// In the main process.
const { app, BrowserWindow } = require('electron')
let win = null
Sending non-standard JavaScript types such as DOM objects or
special Electron objects will throw an exception.

app.whenReady().then(() => {
win = new BrowserWindow({ width: 800, height: 600 })
win.loadURL(`file://${__dirname}/index.html`)
win.webContents.on('did-finish-load', () => {
win.webContents.send('ping', 'whoooooooh!')
})
})
```
:::

```html
<!-- index.html -->
<html>
<body>
<script>
require('electron').ipcRenderer.on('ping', (event, message) => {
console.log(message) // Prints 'whoooooooh!'
})
</script>
</body>
</html>
```
For additional reading, refer to [Electron's IPC guide](../tutorial/ipc.md).

#### `contents.sendToFrame(frameId, channel, ...args)`

Expand Down