Skip to content

Commit

Permalink
docs: remove outdated ipc example (#37539)
Browse files Browse the repository at this point in the history
Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Erick Zhao <erick@hotmail.ca>
  • Loading branch information
trop[bot] and erickzhao committed Mar 9, 2023
1 parent 66683e5 commit c1b8848
Showing 1 changed file with 7 additions and 33 deletions.
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

0 comments on commit c1b8848

Please sign in to comment.