From 46d80e8f05391f24fbe9d48d0f5b69728131f400 Mon Sep 17 00:00:00 2001 From: deepak1556 Date: Mon, 18 May 2015 19:19:33 +0530 Subject: [PATCH] devtools: api to inspect service worker for current webcontents --- atom/browser/api/atom_api_web_contents.cc | 12 ++++++++++++ atom/browser/api/atom_api_web_contents.h | 1 + atom/renderer/lib/web-view/web-view.coffee | 1 + docs/api/web-view-tag.md | 4 ++++ 4 files changed, 18 insertions(+) diff --git a/atom/browser/api/atom_api_web_contents.cc b/atom/browser/api/atom_api_web_contents.cc index e228a064f41..c61a124e481 100644 --- a/atom/browser/api/atom_api_web_contents.cc +++ b/atom/browser/api/atom_api_web_contents.cc @@ -615,6 +615,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()) @@ -657,6 +668,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 e75cfb0267f..1b22a2cbc61 100644 --- a/atom/browser/api/atom_api_web_contents.h +++ b/atom/browser/api/atom_api_web_contents.h @@ -68,6 +68,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/renderer/lib/web-view/web-view.coffee b/atom/renderer/lib/web-view/web-view.coffee index bf163c0cfb5..c450f753060 100644 --- a/atom/renderer/lib/web-view/web-view.coffee +++ b/atom/renderer/lib/web-view/web-view.coffee @@ -268,6 +268,7 @@ registerWebViewElement = -> "replaceMisspelling" "send" "getId" + "inspectServiceWorker" ] # Forward proto.foo* method calls to WebViewImpl.foo*. diff --git a/docs/api/web-view-tag.md b/docs/api/web-view-tag.md index 89ae678b3c4..13bd32d41d7 100644 --- a/docs/api/web-view-tag.md +++ b/docs/api/web-view-tag.md @@ -226,6 +226,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.