diff --git a/shell/browser/ui/inspectable_web_contents.cc b/shell/browser/ui/inspectable_web_contents.cc index b2488e6954f6..cf47c78eb611 100644 --- a/shell/browser/ui/inspectable_web_contents.cc +++ b/shell/browser/ui/inspectable_web_contents.cc @@ -1007,6 +1007,7 @@ void InspectableWebContents::WebContentsDestroyed() { Observe(nullptr); Detach(); embedder_message_dispatcher_.reset(); + frontend_host_.reset(); if (view_ && view_->GetDelegate()) view_->GetDelegate()->DevToolsClosed(); @@ -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_) { @@ -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; diff --git a/spec/api-web-contents-spec.ts b/spec/api-web-contents-spec.ts index cfd366554f32..ba517e831b67 100644 --- a/spec/api-web-contents-spec.ts +++ b/spec/api-web-contents-spec.ts @@ -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', () => {