feat: MessagePorts in the main process (#22404)
This commit is contained in:
parent
c4c0888972
commit
b4d07f76d3
34 changed files with 1316 additions and 113 deletions
|
@ -1593,6 +1593,32 @@ ipcMain.on('ping', (event) => {
|
|||
})
|
||||
```
|
||||
|
||||
#### `contents.postMessage(channel, message, [transfer])`
|
||||
|
||||
* `channel` String
|
||||
* `message` any
|
||||
* `transfer` MessagePortMain[] (optional)
|
||||
|
||||
Send a message to the renderer process, optionally transferring ownership of
|
||||
zero or more [`MessagePortMain`][] objects.
|
||||
|
||||
The transferred `MessagePortMain` objects will be available in the renderer
|
||||
process by accessing the `ports` property of the emitted event. When they
|
||||
arrive in the renderer, they will be native DOM `MessagePort` objects.
|
||||
|
||||
For example:
|
||||
```js
|
||||
// Main process
|
||||
const { port1, port2 } = new MessageChannelMain()
|
||||
webContents.postMessage('port', { message: 'hello' }, [port1])
|
||||
|
||||
// Renderer process
|
||||
ipcRenderer.on('port', (e, msg) => {
|
||||
const [port] = e.ports
|
||||
// ...
|
||||
})
|
||||
```
|
||||
|
||||
#### `contents.enableDeviceEmulation(parameters)`
|
||||
|
||||
* `parameters` Object
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue