diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index 96b767a98817..3a0dfbb5552c 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -679,6 +679,17 @@ void WebContents::UnregisterServiceWorker( callback); } +void WebContents::InspectServiceWorker() { + for (const auto& agent_host : content::DevToolsAgentHost::GetOrCreateAll()) { + if (agent_host->GetType() == + content::DevToolsAgentHost::TYPE_SERVICE_WORKER) { + OpenDevTools(); + storage_->AttachTo(agent_host); + break; + } + } +} + mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder( v8::Isolate* isolate) { if (template_.IsEmpty()) @@ -722,6 +733,7 @@ mate::ObjectTemplateBuilder WebContents::GetObjectTemplateBuilder( .SetMethod("hasServiceWorker", &WebContents::HasServiceWorker) .SetMethod("unregisterServiceWorker", &WebContents::UnregisterServiceWorker) + .SetMethod("inspectServiceWorker", &WebContents::InspectServiceWorker) .Build()); return mate::ObjectTemplateBuilder( diff --git a/atom/browser/api/atom_api_web_contents.h b/atom/browser/api/atom_api_web_contents.h index 204f7d2b6a6f..c7a8bbbfc04f 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -70,6 +70,7 @@ class WebContents : public mate::EventEmitter, void InspectElement(int x, int y); void HasServiceWorker(const base::Callback&); void UnregisterServiceWorker(const base::Callback&); + void InspectServiceWorker(); // Editing commands. void Undo(); diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index 17ad710e2d59..fb2562e0e078 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -371,6 +371,10 @@ void Window::InspectElement(int x, int y) { window_->InspectElement(x, y); } +void Window::InspectServiceWorker() { + window_->InspectServiceWorker(); +} + void Window::FocusOnWebView() { window_->FocusOnWebView(); } @@ -544,7 +548,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 cd1573d48d09..71de91df6913 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -121,6 +121,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 dd1a389228c6..7fb0de344472 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -314,6 +314,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 d95f7faf9178..ce829c71b533 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/atom/renderer/lib/web-view/web-view.coffee b/atom/renderer/lib/web-view/web-view.coffee index 8ecbb8c46491..a4edc58a10f2 100644 --- a/atom/renderer/lib/web-view/web-view.coffee +++ b/atom/renderer/lib/web-view/web-view.coffee @@ -270,6 +270,7 @@ registerWebViewElement = -> "replaceMisspelling" "send" "getId" + "inspectServiceWorker" ] # Forward proto.foo* method calls to WebViewImpl.foo*. diff --git a/docs/api/browser-window.md b/docs/api/browser-window.md index 226faa0b043f..30055dccb0af 100644 --- a/docs/api/browser-window.md +++ b/docs/api/browser-window.md @@ -524,6 +524,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() diff --git a/docs/api/web-view-tag.md b/docs/api/web-view-tag.md index 96484649ceb8..705014cf6a18 100644 --- a/docs/api/web-view-tag.md +++ b/docs/api/web-view-tag.md @@ -238,6 +238,10 @@ Returns whether guest page has a devtools window attached. Starts inspecting element at position (`x`, `y`) of guest page. +### ``.inspectServiceWorker() + +Opens the devtools for the service worker context present in the guest page. + ### ``.undo() Executes editing command `undo` in page.