8000 fix: check WebContents before emitting render-process-gone event by zcbenz · Pull Request #27730 · electron/electron · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: check WebContents before emitting render-process-gone event #27730

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

Merged
merged 1 commit into from
Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions shell/browser/api/electron_api_web_contents.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1407,7 +1407,13 @@ void WebContents::RenderViewDeleted(content::RenderViewHost* render_view_host) {
}

void WebContents::RenderProcessGone(base::TerminationStatus status) {
auto weak_this = GetWeakPtr();
Emit("crashed", status == base::TERMINATION_STATUS_PROCESS_WAS_KILLED);

// User might destroy WebContents in the crashed event.
if (!weak_this)
return;

v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
v8::HandleScope handle_scope(isolate);
gin_helper::Dictionary details = gin_helper::Dictionary::CreateEmpty(isolate);
Expand Down
11 changes: 11 additions & 0 deletions spec-main/api-web-contents-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2007,6 +2007,17 @@ describe('webContents module', () => {
});
});

describe('crashed event', () => {
it('does not crash main process when destroying WebContents in it', (done) => {
const contents = (webContents as any).create({ nodeIntegration: true });
contents.once('crashed', () => {
contents.destroy();
done();
});
contents.loadURL('about:blank').then(() => contents.forcefullyCrashRenderer());
});
});

it('emits a cancelable event before creating a child webcontents', async () => {
const w = new BrowserWindow({
show: false,
Expand Down
0