Skip to content

Commit

Permalink
fix: crash on browserView.webContents.destroy() (#31794)
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Nov 15, 2021
1 parent 22f863b commit 7e328c4
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 1 addition & 2 deletions shell/browser/api/electron_api_web_contents.cc
Expand Up @@ -983,8 +983,7 @@ void WebContents::DeleteThisIfAlive() {
void WebContents::Destroy() {
// The content::WebContents should be destroyed asyncronously when possible
// as user may choose to destroy WebContents during an event of it.
if (Browser::Get()->is_shutting_down() || IsGuest() ||
type_ == Type::kBrowserView) {
if (Browser::Get()->is_shutting_down() || IsGuest()) {
DeleteThisIfAlive();
} else {
base::PostTask(FROM_HERE, {content::BrowserThread::UI},
Expand Down
11 changes: 10 additions & 1 deletion spec-main/api-browser-view-spec.ts
Expand Up @@ -151,14 +151,23 @@ describe('BrowserView module', () => {
w.addBrowserView(view);
});

it('does not crash if the BrowserView webContents are destroyed prior to window removal', () => {
it('does not crash if the BrowserView webContents are destroyed prior to window addition', () => {
expect(() => {
const view1 = new BrowserView();
(view1.webContents as any).destroy();
w.addBrowserView(view1);
}).to.not.throw();
});

it('does not crash if the webContents is destroyed after a URL is loaded', () => {
view = new BrowserView();
expect(async () => {
view.setBounds({ x: 0, y: 0, width: 400, height: 300 });
await view.webContents.loadURL('data:text/html,hello there');
view.webContents.destroy();
}).to.not.throw();
});

it('can handle BrowserView reparenting', async () => {
view = new BrowserView();

Expand Down

0 comments on commit 7e328c4

Please sign in to comment.