8000 fix: render process crash handling by trop[bot] · Pull Request #34430 · electron/electron · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: render process crash handling #34430

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
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
9 changes: 8 additions & 1 deletion shell/browser/api/electron_api_web_frame_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -189,13 +189,20 @@ const mojo::Remote<mojom::ElectronRenderer>& WebFrameMain::GetRendererApi() {
}

void WebFrameMain::MaybeSetupMojoConnection() {
if (render_frame_disposed_) {
// RFH may not be set yet if called between when a new RFH is created and
// before it's been swapped with an old RFH.
LOG(INFO) << "Attempt to setup WebFrameMain connection while render frame "
"is disposed";
return;
}

if (!renderer_api_) {
pending_receiver_ = renderer_api_.BindNewPipeAndPassReceiver();
renderer_api_.set_disconnect_handler(base::BindOnce(
&WebFrameMain::OnRendererConnectionError, weak_factory_.GetWeakPtr()));
}

// Render frame should exist when this method is called.
DCHECK(render_frame_);

// Wait for RenderFrame to be created in renderer before accessing remote.
Expand Down
3 changes: 3 additions & 0 deletions shell/browser/electron_browser_client.cc
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,9 @@ void ElectronBrowserClient::RenderProcessWillLaunch(
new extensions::MessagingAPIMessageFilter(process_id, browser_context));
#endif

// Remove in case the host is reused after a crash, otherwise noop.
host->RemoveObserver(this);

// ensure the ProcessPreferences is removed later
host->AddObserver(this);
}
Expand Down
27 changes: 27 additions & 0 deletions spec-main/api-web-frame-main-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,33 @@ describe('webFrameMain module', () => {
expect(w.webContents.mainFrame).to.equal(mainFrame);
expect(mainFrame.url).to.equal(crossOriginUrl);
});

it('recovers from renderer crash on same-origin', async () => {
const server = await createServer();
// Keep reference to mainFrame alive throughout crash and recovery.
const { mainFrame } = w.webContents;
await w.webContents.loadURL(server.url);
w.webContents.forcefullyCrashRenderer();
await w.webContents.loadURL(server.url);
// Log just to keep mainFrame in scope.
console.log('mainFrame.url', mainFrame.url);
});

// Fixed by #34411
it('recovers from renderer crash on cross-origin', async () => {
const server = await createServer();
// 'localhost' is treated as a separate origin.
const crossOriginUrl = server.url.replace('127.0.0.1', 'localhost');
// Keep reference to mainFrame alive throughout crash and recovery.
const { mainFrame } = w.webContents;
await w.webContents.loadURL(server.url);
w.webContents.forcefullyCrashRenderer();
// A short wait seems to be required to reproduce the crash.
await new Promise(resolve => setTimeout(resolve, 100));
await w.webContents.loadURL(crossOriginUrl);
// Log just to keep mainFrame in scope.
console.log('mainFrame.url', mainFrame.url);
});
});

describe('webFrameMain.fromId', () => {
Expand Down
0