Bug 1360196 - Implement about:devtools-toolbox URL parameter in the network monitor. r=rickychien draft
authorAlexandre Poirot <poirot.alex@gmail.com>
Thu, 27 Apr 2017 11:23:34 +0200
changeset 570015 e46a44aacd119ab6b09868764a8787215e6500b7
parent 569501 abe5868346c7abb5b0bdf76f29bc3d9f839461f5
child 570017 445ac4d8f2c2d3e4942d9c99c8eb314b3b2e40d0
push id56364
push userbmo:poirot.alex@gmail.com
push dateFri, 28 Apr 2017 08:46:37 +0000
reviewersrickychien
bugs1360196
milestone55.0a1
Bug 1360196 - Implement about:devtools-toolbox URL parameter in the network monitor. r=rickychien MozReview-Commit-ID: HtLwJdVsaIt
devtools/client/netmonitor/index.html
--- a/devtools/client/netmonitor/index.html
+++ b/devtools/client/netmonitor/index.html
@@ -46,11 +46,42 @@
           }, actions);
         },
 
         destroy() {
           unmountComponentAtNode(this.mount);
           return NetMonitorController.shutdownNetMonitor();
         }
       };
+
+      // Implement support for chrome://devtools/content/netmonitor/index.html?type=tab&id=1234 URLs
+      // where 1234 is the tab id, you can retrieve from about:debugging#tabs links.
+      // Simply copy the id from about:devtools-toolbox?type=tab&id=1234 URLs.
+
+      // URL constructor doesn't support chrome: scheme
+      let href = window.location.href.replace(/chrome:/, "http://");
+      let url = new window.URL(href);
+
+      // If query parameters are given in a chrome tab, the inspector is running in standalone.
+      if (window.location.protocol === "chrome:" && url.search.length > 1) {
+        const { targetFromURL } = require("devtools/client/framework/target-from-url");
+
+        (async function () {
+          let target = await targetFromURL(url);
+          // Start the network event listening as it is done in the toolbox code
+          await target.activeConsole.startListeners([
+            "NetworkActivity",
+          ]);
+          // Create a fake toolbox object
+          let toolbox = {
+            target,
+            viewSourceInDebugger() {
+              throw new Error("toolbox.viewSourceInDebugger is not implement from a tab");
+            }
+          };
+          window.Netmonitor.bootstrap({ toolbox });
+        })().catch(e => {
+          window.alert("Unable to start the network monitor:" + e.message + "\n" + e.stack);
+        });
+      }
     </script>
   </body>
 </html>