Skip to content

Commit 71e3296

Browse files
feat: add new render-process-gone event (#24309)
Co-authored-by: Samuel Attard <[email protected]>
1 parent 67002fd commit 71e3296

File tree

4 files changed

+66
-1
lines changed

4 files changed

+66
-1
lines changed

docs/api/web-contents.md

+24-1
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ win.webContents.on('will-prevent-unload', (event) => {
325325
})
326326
```
327327

328-
#### Event: 'crashed'
328+
#### Event: 'crashed' _Deprecated_
329329

330330
Returns:
331331

@@ -334,6 +334,29 @@ Returns:
334334

335335
Emitted when the renderer process crashes or is killed.
336336

337+
**Deprecated:** This event is superceded by the `render-process-gone` event
338+
which contains more information about why the render process dissapeared. It
339+
isn't always because it crashed. The `killed` boolean can be replaced by
340+
checking `reason === 'killed'` when you switch to that event.
341+
342+
#### Event: 'render-process-gone'
343+
344+
Returns:
345+
346+
* `event` Event
347+
* `details` Object
348+
* `reason` String - The reason the render process is gone. Possible values:
349+
* `clean-exit` - Process exited with an exit code of zero
350+
* `abnormal-exit` - Process exited with a non-zero exit code
351+
* `killed` - Process was sent a SIGTERM or otherwise killed externally
352+
* `crashed` - Process crashed
353+
* `oom` - Process ran out of memory
354+
* `launch-failure` - Process never successfully launched
355+
* `integrity-failure` - Windows code integrity checks failed
356+
357+
Emitted when the renderer process unexpectedly dissapears. This is normally
358+
because it was crashed or killed.
359+
337360
#### Event: 'unresponsive'
338361

339362
Emitted when the web page becomes unresponsive.

lib/browser/guest-view-manager.js

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const supportedWebViewEvents = [
3232
'focus-change',
3333
'close',
3434
'crashed',
35+
'render-process-gone',
3536
'plugin-crashed',
3637
'destroyed',
3738
'page-title-updated',

shell/browser/api/electron_api_web_contents.cc

+5
Original file line numberDiff line numberDiff line change
@@ -991,6 +991,11 @@ void WebContents::RenderViewDeleted(content::RenderViewHost* render_view_host) {
991991

992992
void WebContents::RenderProcessGone(base::TerminationStatus status) {
993993
Emit("crashed", status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);
994+
v8::HandleScope handle_scope(isolate());
995+
gin_helper::Dictionary details =
996+
gin_helper::Dictionary::CreateEmpty(isolate());
997+
details.Set("reason", status);
998+
Emit("render-process-gone", details);
994999
}
9951000

9961001
void WebContents::PluginCrashed(const base::FilePath& plugin_path,

shell/browser/api/electron_api_web_contents.h

+36
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,42 @@ namespace network {
6060
class ResourceRequestBody;
6161
}
6262

63+
namespace gin {
64+
65+
template <>
66+
struct Converter<base::TerminationStatus> {
67+
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
68+
const base::TerminationStatus& status) {
69+
switch (status) {
70+
case base::TERMINATION_STATUS_NORMAL_TERMINATION:
71+
return gin::ConvertToV8(isolate, "clean-exit");
72+
case base::TERMINATION_STATUS_ABNORMAL_TERMINATION:
73+
return gin::ConvertToV8(isolate, "abnormal-exit");
74+
case base::TERMINATION_STATUS_PROCESS_WAS_KILLED:
75+
return gin::ConvertToV8(isolate, "killed");
76+
case base::TERMINATION_STATUS_PROCESS_CRASHED:
77+
return gin::ConvertToV8(isolate, "crashed");
78+
case base::TERMINATION_STATUS_STILL_RUNNING:
79+
return gin::ConvertToV8(isolate, "still-running");
80+
case base::TERMINATION_STATUS_LAUNCH_FAILED:
81+
return gin::ConvertToV8(isolate, "launch-failed");
82+
case base::TERMINATION_STATUS_OOM:
83+
return gin::ConvertToV8(isolate, "oom");
84+
#if defined(OS_WIN)
85+
case base::TERMINATION_STATUS_INTEGRITY_FAILURE:
86+
return gin::ConvertToV8(isolate, "integrity-failure");
87+
#endif
88+
case base::TERMINATION_STATUS_MAX_ENUM:
89+
NOTREACHED();
90+
return gin::ConvertToV8(isolate, "");
91+
}
92+
NOTREACHED();
93+
return gin::ConvertToV8(isolate, "");
94+
}
95+
};
96+
97+
} // namespace gin
98+
6399
namespace electron {
64100

65101
class ElectronBrowserContext;

0 commit comments

Comments
 (0)