diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index f59b72bd0c9c..aa9f539bd93a 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -895,10 +895,10 @@ void WebContents::DevToolsOpened() { managed_web_contents()->CallClientFunction( "DevToolsAPI.setInspectedTabId", &tab_id, nullptr, nullptr); - // Inherit owner window in devtools. + // Inherit owner window in devtools when it doesn't have one. auto* devtools = managed_web_contents()->GetDevToolsWebContents(); - if (owner_window() && - !devtools->GetUserData(NativeWindowRelay::UserDataKey())) + bool has_window = devtools->GetUserData(NativeWindowRelay::UserDataKey()); + if (owner_window() && !has_window) handle->SetOwnerWindow(devtools, owner_window()); Emit("devtools-opened"); @@ -1179,7 +1179,8 @@ void WebContents::OpenDevTools(mate::Arguments* args) { std::string state; if (type_ == WEB_VIEW || !owner_window()) { state = "detach"; - } else if (args && args->Length() == 1) { + } + if (args && args->Length() == 1) { bool detach = false; mate::Dictionary options; if (args->GetNext(&options)) { diff --git a/docs/api/web-contents.md b/docs/api/web-contents.md index 4def99b9e16c..1a346c968815 100644 --- a/docs/api/web-contents.md +++ b/docs/api/web-contents.md @@ -1144,6 +1144,9 @@ app.once('ready', () => { Opens the devtools. +When `contents` is a `` tag, the `mode` would be `detach` by default, +explicitly passing an empty `mode` can force using last used dock state. + #### `contents.closeDevTools()` Closes the devtools.