Skip to content
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

fix: clean up devtools frontend_host on webcontents destroy #40666

Merged
merged 3 commits into from Dec 1, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 3 additions & 2 deletions shell/browser/ui/inspectable_web_contents.cc
Expand Up @@ -1007,6 +1007,7 @@ void InspectableWebContents::WebContentsDestroyed() {
Observe(nullptr);
Detach();
embedder_message_dispatcher_.reset();
frontend_host_.reset();

if (view_ && view_->GetDelegate())
view_->GetDelegate()->DevToolsClosed();
Expand Down Expand Up @@ -1052,7 +1053,7 @@ void InspectableWebContents::OnWebContentsFocused(

void InspectableWebContents::ReadyToCommitNavigation(
content::NavigationHandle* navigation_handle) {
if (navigation_handle->IsInMainFrame()) {
if (navigation_handle->IsInPrimaryMainFrame()) {
if (navigation_handle->GetRenderFrameHost() ==
GetDevToolsWebContents()->GetPrimaryMainFrame() &&
frontend_host_) {
Expand All @@ -1069,7 +1070,7 @@ void InspectableWebContents::ReadyToCommitNavigation(

void InspectableWebContents::DidFinishNavigation(
content::NavigationHandle* navigation_handle) {
if (navigation_handle->IsInMainFrame() ||
if (navigation_handle->IsInPrimaryMainFrame() ||
!navigation_handle->GetURL().SchemeIs("chrome-extension") ||
!navigation_handle->HasCommitted())
return;
Expand Down
18 changes: 18 additions & 0 deletions spec/api-web-contents-spec.ts
Expand Up @@ -639,6 +639,24 @@ describe('webContents module', () => {
await devtoolsOpened;
expect(w.webContents.getDevToolsTitle()).to.equal('myTitle');
});

it('can re-open devtools', async () => {
const w = new BrowserWindow({ show: false });
const devtoolsOpened = once(w.webContents, 'devtools-opened');
w.webContents.openDevTools({ mode: 'detach', activate: true });
await devtoolsOpened;
expect(w.webContents.isDevToolsOpened()).to.be.true();

const devtoolsClosed = once(w.webContents, 'devtools-closed');
w.webContents.closeDevTools();
await devtoolsClosed;
expect(w.webContents.isDevToolsOpened()).to.be.false();

const devtoolsOpened2 = once(w.webContents, 'devtools-opened');
w.webContents.openDevTools({ mode: 'detach', activate: true });
await devtoolsOpened2;
expect(w.webContents.isDevToolsOpened()).to.be.true();
});
});

describe('setDevToolsTitle() API', () => {
Expand Down