---
title: roElectronEvent
slug: develop/roelectronevent
createdAt: 2025-07-22T16:29:53.000Z
---

Events from roElectron are delivered to the supplied `message_port` as *roElectronEvent* objects. Call `GetData()` on the event to retrieve an associative array describing it. The `reason` key identifies the event type, for example:

- `message`: A message was sent from the JavaScript side using the *MessagePort* class; the payload is in the `message` key.
- `process_exit`: The Electron process exited. The `exit_code` contains the exit status.

## <font color="#0C121D">ifUserData</font>

### <font color="#0C121D">SetUserData(user\_data As Object)</font>

<font color="#0C121D">Sets the user data that will be returned when events are raised.</font>

### <font color="#0C121D">GetUserData() As Object</font>

<font color="#0C121D">Returns the user data that has previously been set via `SetUserData()`. It will return `Invalid` if no data has been set.</font>

## <font color="#0C121D">ifElectronEvent</font>

### <font color="#0C121D">GetData() As roAssociativeArray</font>

<font color="#0C121D">Returns the event data as an associative array with the following key/value pairs\:</font>

- <font color="#0C121D">`reason` string\: The cause of the event, which can be one of the following\:</font>
  - <font color="#0C121D">`process_exit`\: The Electron instance has exited.</font>
  - <font color="#0C121D">`message`\: The Electron instance has sent a message\*.\*</font>
- <font color="#0C121D">`exit_code` number\:  The value of this field is set by the Electron application when it exits (\~\~\~\~). The Electron process exit code is only defined in OS 8.2 and later OS versions. Note that the Electron script can also use these codes for its own purposes. </font>
- <font color="#0C121D">`message` string\: If the `reason` field value is `message`, this field returns the contents of the message.</font>

## Example

```<font
msgPort = CreateObject("roMessagePort")

electronConfig = {
    app_name: "MyApp"
    message_port: msgPort
}
electron = CreateObject("roElectron", "file://sd:/app.asar", electronConfig)

electron.PostJsMessage({ command: "start" })

while true
    msg = wait(0, msgPort)

    if type(msg) = "roElectronEvent" then
        data = msg.GetData()
        print data.reason
    end if
end while
```

