diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index b71499d3699c..74f0ba69ca45 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -351,6 +351,10 @@ void Window::InspectElement(int x, int y) { window_->InspectElement(x, y); } +void Window::InspectServiceWorker() { + window_->InspectServiceWorker(); +} + void Window::FocusOnWebView() { window_->FocusOnWebView(); } @@ -524,7 +528,8 @@ void Window::BuildPrototype(v8::Isolate* isolate, &Window::ShowDefinitionForSelection) #endif .SetMethod("_getWebContents", &Window::GetWebContents) - .SetMethod("_getDevToolsWebContents", &Window::GetDevToolsWebContents); + .SetMethod("_getDevToolsWebContents", &Window::GetDevToolsWebContents) + .SetMethod("inspectServiceWorker", &Window::InspectServiceWorker); } } // namespace api diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index d5c3ceedd2eb..d0d7b2621c56 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -116,6 +116,7 @@ class Window : public mate::EventEmitter, void CloseDevTools(); bool IsDevToolsOpened(); void InspectElement(int x, int y); + void InspectServiceWorker(); void FocusOnWebView(); void BlurWebView(); bool IsWebViewFocused(); diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 5bef1acfb872..9d24e68c8f42 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -317,6 +317,17 @@ void NativeWindow::InspectElement(int x, int y) { agent->InspectElement(x, y); } +void NativeWindow::InspectServiceWorker() { + for (const auto& agent_host : content::DevToolsAgentHost::GetOrCreateAll()) { + if (agent_host->GetType() == + content::DevToolsAgentHost::TYPE_SERVICE_WORKER) { + OpenDevTools(true); + inspectable_web_contents()->AttachTo(agent_host); + break; + } + } +} + void NativeWindow::FocusOnWebView() { GetWebContents()->GetRenderViewHost()->Focus(); } diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 32c3493cdbf8..05742a3880da 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -153,6 +153,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate, virtual void CloseDevTools(); virtual bool IsDevToolsOpened(); virtual void InspectElement(int x, int y); + virtual void InspectServiceWorker(); virtual void FocusOnWebView(); virtual void BlurWebView(); diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index f8ff8e7b9e0c..e20d809a5e7b 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -500,6 +500,10 @@ Toggle the developer tools. Starts inspecting element at position (`x`, `y`). +### BrowserWindow.inspectServiceWorker() + +Opens the developer tools for the service worker context present in the web contents. + ### BrowserWindow.focusOnWebView() ### BrowserWindow.blurWebView()