]> khamidou — GitHub mirrors - electron.git/commitdiff
devtools: api to inspect service worker for current webcontents
authordeepak1556 <hop2deep@gmail.com>
Mon, 18 May 2015 13:49:33 +0000 (19:19 +0530)
committerdeepak1556 <hop2deep@gmail.com>
Mon, 18 May 2015 13:49:33 +0000 (19:19 +0530)
atom/browser/api/atom_api_web_contents.cc
atom/browser/api/atom_api_web_contents.h
atom/renderer/lib/web-view/web-view.coffee
docs/api/web-view-tag.md

index e228a064f4138d22403c8df08e705b07e9b40da0..c61a124e4810d191dbe0a412c1321821233bf8f9 100644 (file)
@@ -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(
index e75cfb0267f0b784b82727fbe969578eda1099f6..1b22a2cbc61d46d8de2648145f270b58609b7ef1 100644 (file)
@@ -68,6 +68,7 @@ class WebContents : public mate::EventEmitter,
   void InspectElement(int x, int y);
   void HasServiceWorker(const base::Callback<void(bool)>&);
   void UnregisterServiceWorker(const base::Callback<void(bool)>&);
+  void InspectServiceWorker();
 
   // Editing commands.
   void Undo();
index bf163c0cfb5c7e59302cae0e4bef531eda37002a..c450f753060c08691f92274b22495d25f59119be 100644 (file)
@@ -268,6 +268,7 @@ registerWebViewElement = ->
     "replaceMisspelling"
     "send"
     "getId"
+    "inspectServiceWorker"
   ]
 
   # Forward proto.foo* method calls to WebViewImpl.foo*.
index 89ae678b3c4679a6bd802d502104b68f85ce6647..13bd32d41d7937ccc83dc69cf4c14578612cdbe5 100644 (file)
@@ -226,6 +226,10 @@ Returns whether guest page has a devtools window attached.
 
 Starts inspecting element at position (`x`, `y`) of guest page.
 
+### `<webview>`.inspectServiceWorker()
+
+Opens the devtools for the service worker context present in the guest page.
+
 ### `<webview>`.undo()
 
 Executes editing command `undo` in page.